Tuesday 20 August 2013

Reloading listview displays old and new content

Reloading listview displays old and new content

I have a custom listview that displays the contents of a database table.
The use can add a new item to the database and the Listview will reload to
display the newly added item as well as everything else in the table.
However using the below code when the listview is updated it will show
both the content from the table for the add and after the add. For
example:
The list view would look like:
Item 1
Item 2
Item 3
Then a user adds a new item and it should look like
Item 1
Item 2
Item 3
Item 4
But instead it displays
Item 1
Item 2
Item 3
Item 1
Item 2
Item 3
Item 4
I use this code to update the Listview
m_adapter.clear();
for (int i = 0; i < db.getAllLists().size(); i++) {
m_adapter.add(db.getAllLists().get(i));
}
m_adapter.notifyDataSetChanged();
Let me know if you need to see any other code, thank you

No comments:

Post a Comment