Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>ListView is a tricky beast.</p> <p>Your second question first: you're seeing duplicates because ListView re-uses Views via convertView, but you're not making sure to reset all aspects of the converted view. Make sure that the code path for <code>convertView!=null</code> properly sets all of the data for the view, and everything should work properly.</p> <p>You'll want your <code>getView()</code> method to look roughly like the following if you're using custom views:</p> <pre><code>@Override public View getView(int position, View convertView, ViewGroup parent) { final MyCustomView v = convertView!=null ? (MyCustomView)convertView : new MyCustomView(); v.setMyData( listAdapter.get(position) ); return v; } </code></pre> <p>If you're not using your own custom view, just replace the call to <code>new MyCustomView()</code> with a call to <code>inflater.inflate(R.layout.my_layout,null)</code></p> <p>As to your first question, you'll want to watch Romain's techtalk on ListView performance here: <a href="http://code.google.com/events/io/sessions/TurboChargeUiAndroidFast.html" rel="noreferrer">http://code.google.com/events/io/sessions/TurboChargeUiAndroidFast.html</a></p> <p>From his talk and in order of importance from my own experience,</p> <ul> <li>Use convertView</li> <li>If you have images, don't scale your images on the fly. Use Bitmap.createScaledBitmap to create a scaled bitmap and put that into your views</li> <li>Use a ViewHolder so you don't have to call a bunch of findViewByIds() every time</li> <li>Decrease the complexity of the views in your listview. The fewer subviews, the better. RelativeLayout is much better at this than, say, LinearLayout. And make sure to use if you're implementing custom views.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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