mListAdapter.remove(x); // to remove an item and mListAdapter.invalidate(); // to refresh the content
or mListAdapter.notifyDataSetChanged(); try it.... On Mar 23, 10:20 am, kavitha <[email protected]> wrote: > thanks for response patbenatar,,, > > can u please post the example code here,, > > wat i am doing here is, > Initially in oncreate populate list once,,then from handlerthread,updating > list from a handle,and i am using same arraylist ,,clearing same arraylist > and populating new items,,then setAdapter to list > > old list items doesnt get cleared,,,new items add up to old ones > > > > On Tue, Mar 23, 2010 at 1:36 AM, patbenatar <[email protected]> wrote: > > What you want to be doing here is getting a handle on the active > > ArrayList being used by the ListView right now and then manipulate > > that data directly and when you're done fire notifyDataSetChanged on > > that adapter. It looks from your code snippet above that you are > > creating a new ArrayList every time you want to manipulate the data. > > Just work with the one you already have, you can clear it and re-add > > items or delete items or whatever you want. This is what I have done > > to get notifyDataSetChanged to work on my ListViews. > > > On Mar 19, 10:34 pm, kavitha <[email protected]> wrote: > > > Thanks MarkMurphy. > > > > But still i am not able to clear list items and populate with new > > > items,,,new items get added up to old items. > > > > my code is this > > > > ArrayAdapter<String> adapter; > > > ArrayList<String> results=new ArrayList<String>(); > > > > private void populateStationsList(RadioStation[] radioStation){ > > > results.clear(); > > > stationsList=(ListView) findViewById(R.id.station_list); > > > > stationsList.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL); > > > > for (int i=0; i<radioStation.length; i++) { > > > String s=radioStation[i].getName(); > > > > results.add(s); > > > } > > > stationsList.setSelectionFromTop(1, 1); > > > > adapter = new ArrayAdapter<String>(this, > > > android.R.layout.simple_list_item_1, results); > > > > stationsList.setAdapter(adapter); > > > adapter.notifyDataSetChanged(); > > > stationsList.setOnItemClickListener(this); > > > > } > > > > On Fri, Mar 19, 2010 at 6:31 PM, Mark Murphy <[email protected] > > >wrote: > > > > > kavitha wrote: > > > > > Hi All, > > > > > > How to remove all Items in a ListView in android. > > > > > > I want to remove all items in list view and populate with new items > > > > > dynamically from a background thread. > > > > > > Please tell,,this is very urgent. > > > > > Replace the adapter used by the ListView. > > > > > -- > > > > Mark Murphy (a Commons Guy) > > > >http://commonsware.com|http://twitter.com/commonsguy > > > > > Android Training in US: 14-18 June 2010:http://bignerdranch.com > > > > > -- > > > > You received this message because you are subscribed to the Google > > > > Groups "Android Developers" group. > > > > To post to this group, send email to > > [email protected] > > > > To unsubscribe from this group, send email to > > > > [email protected]<android-developers%2bunsubs[email protected]><android-developers%2Bunsubs > > [email protected]> > > > > For more options, visit this group at > > > >http://groups.google.com/group/android-developers?hl=en > > > > > To unsubscribe from this group, send email to android-developers+ > > > > unsubscribegooglegroups.com or reply to this email with the words > > "REMOVE > > > > ME" as the subject. > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Developers" group. > > To post to this group, send email to [email protected] > > To unsubscribe from this group, send email to > > [email protected]<android-developers%2bunsubs[email protected]> > > For more options, visit this group at > >http://groups.google.com/group/android-developers?hl=en > > > To unsubscribe from this group, send email to android-developers+ > > unsubscribegooglegroups.com or reply to this email with the words "REMOVE > > ME" as the subject. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

