Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are correct that <code>ListView</code> is reusing views in different places on the screen. It's an optimization to keep memory use reasonable and speedy by not allocating new views all the time.</p> <p>Chances are that you're using <code>LiewView</code> incorrectly. Watch <a href="http://www.youtube.com/watch?v=wDBM6wVEO70" rel="noreferrer">this talk on how to properly use <code>ListView</code></a> to get the whole story, but here's the highlights:</p> <ol> <li>"Position" refers to the location of your data in the adapter list. If your adapter data is in an array, this would be the index into that array.</li> <li>"ID" refers to the value of the data itself. If you have a list of names and resort them, their position will change, but their ID will not.</li> <li>"Index" refers to the relative location of a view with respect to the viewable screen area. You'll probably never need this.</li> <li>Do not manipulate views (or attempt to cache them) outside of your adapter's <code>getView()</code> method or you will get strange behavior.</li> <li>If the call to <code>getView(int, View, ViewGroup)</code> provides a view instance, populate its fields instead of inflating totally new views. Assuming you've correctly implemented <code>getItemType()</code>, you'll always get the right <code>View</code> type to repopulate. </li> <li>Make your <code>getView()</code> method as fast as you possibly can, and only do heavy lifting on other threads.</li> <li>Just because the container called <code>getView()</code> doesn't necessarily mean the data will be displayed. The framework uses these for measurement purposes. Since the work could be thrown away, this is another reason to make sure that <code>getView()</code> is as fast as you can make it.</li> <li>When something happens to your data which you need to show on screen, say your download is complete, that's when you call <code>notifyDataSetChanged()</code>. Don't fiddle with the views directly, they'll be populated on the next UI loop when it gets redrawn.</li> </ol> <p>Having just spent a few days reworking a <code>ListView</code> that was implemented naively, I feel your pain. The results have been worth it, though!</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