I have one android activity which extends ListActivity. Every time list items is pressed the activity should change its state(new list adapter) and reload. To do that on item click I create new ArrayAdapter for the list and set it but instead of resetting the list of items new items are just appended to the older ones. How can I erase old list items and set new ones?
private void update() {
if (flag == null) {
//do nothing
} else {
list_items = new Vector();
list_items.addAll(getNewListItems());
}
String[] items = new String[list_items.size()];
for (int i=0; i<list_items.size(); i++)
items[i] = list_items.get(i).toString();
setListAdapter(new ArrayAdapter<String>(this, R.layout.menu_layout, R.id.label, items));
}
Make a custom adapter, then
You can just remove old items add your new items in your
String[] items.And just call
notifyDataSetChanged()to your adapter…Then you don’t have to call every time new adapter..