how to remove listview items in android

Posted by kavitha on Stack Overflow See other posts from Stack Overflow or by kavitha
Published on 2010-04-01T06:44:08Z Indexed on 2010/04/01 6:53 UTC
Read the original article Hit count: 709

Filed under:

Hi all,,

Can somebody please give me an example code of removing all ListView items and replacing with new items.

I tried replacing the adapter items.Still no results.

my code is

at first i am calling

populateList(){

   results -populated arraylist with strings

   ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, results);
 listview.setAdapter(adapter);
 adapter.notifyDataSetChanged();
 listview.setOnItemClickListener(this);

}

// now populating list again

repopulateList(){

 results1-populated arraylist with strings

  ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, results1);
 listview.setAdapter(adapter1);
 adapter1.notifyDataSetChanged();
 listview.setOnItemClickListener(this);

}

Here replpulateList() method will add to listview items. It doent remove/replace all listview items.

Please Help.

© Stack Overflow or respective owner

Related posts about android