Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>How do I retrieve data from the ListView?</p> </blockquote> <p>If you want to know which item in the <code>ListView</code> was clicked, you use an <code>OnItemClickListener</code> and <code>Listview.setOnItemClickListener</code>. There's an example of this in the <a href="http://developer.android.com/resources/tutorials/views/hello-listview.html" rel="nofollow noreferrer">Hello ListView</a> tutorial.</p> <p>Once you know which item is selected, you then know the position of that item in the overall <code>Adapter</code>, and you have the <code>View</code>. You can use the View to get sub-elements if needed, generally though the position is enough to let you know what part of your "model" was clicked. In your example it would tell you exactly which item in your <code>List&lt;MyClass&gt;</code> was clicked.</p> <p>If you want to distinguish between the list item being clicked, and a focusable view in the list item (like a checkbox), then that's a little more involved. The checkbox, by default, will hikack the focus from the list item. You can toggle this though and make it false, depending on what you're trying to do. See <a href="https://stackoverflow.com/questions/1121192/android-custom-listview-unable-to-click-on-items">this question</a> for more info. </p> <p>If you need to distinguish between the ListView item click and the CheckBox click, there are several ways. One way is to just maintain the state of whether or not an item is clicked inside the adapter. </p> <p>For example:</p> <p><a href="http://code.google.com/p/android-in-practice/source/browse/trunk/ch04/MyMovies/src/com/manning/aip/mymovies/MovieAdapter.java" rel="nofollow noreferrer">MovieAdapter</a></p> <p><a href="http://code.google.com/p/android-in-practice/source/browse/trunk/ch04/MyMovies/src/com/manning/aip/mymovies/MyMovies.java" rel="nofollow noreferrer">MyMovies (ListView)</a></p> <p>Then you just use the normal "onListItemClick" and the adapter to tell what is clicked and what isn't. (This is just one way to do this, there are several.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload