On Friday, May 16, 2014 11:58:17 AM UTC-7, plnelson wrote: > > ...In MyListActivity, which is a ListActivity . . . > > public static ListView lv; // my ListView in the code >
Why is this public and static? > ...the data source is an ArrayList called listItems. The first time around > it has 12 items in it; later I clear it and add in 6 items. (see below) > > public static ArrayList<String>listItems=new ArrayList<String>(); > > Why is this public and static? > ... in my adapter, which is a BaseAdapter, my override of getCount() looks > like this. After shrinking listItems to 6 it correctly returns 6. > > @Override > public int getCount() { > return listItems.size(); > } > > ... To shrink my dataset to 6 I first do a > > listItems.clear(); > lv.invalidate(); // my (failed) attempt to get lv to reset its count > Invalidate doesn't do what you think it does. That has to do with the rendering of the view on screen, not the contents of the adapter that the ListView knows about. > ... and then add in the 6 new items. After adding each item to listItems I > do a notifyDataSetChanged() on the adapter. What I've noticed is that if* > I do an lv.getCount it returns 12, i.e., the value it was before doing the > listItems.clear()* and invalidate(). Why does the ListView still think > it's 12? How do I reset it? Is that why the adapter thinks it's too big? > Try setting a new (non-public, non-static) adapter into the ListView instead. Never change the contents of the data in an adapter after you've given it to the ListView. Make a deep copy of the data before sending it if you have to. Doug -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.