Skip to content Skip to sidebar Skip to footer

NotifyDataSetChange Does Not Refresh ListView With Custom Adapter

I am trying to figure this out, but i just cant see what i am doing wrong. I want to dynamically fill ListView with products (add product to array then refresh list, basically for

Solution 1:

Can you post the ReceiptListAdapter code? That is where you need to make the connection between the data source and the UI. You do this by registering ContentObservers on the database and then the ListView registers its ContentObserver with the Adapter. The Adapter notifies the ListView to update by calling the onChanged() method of the ListView DataSetObserver.

When working with a database, a common choice is to use a CursorLoader to fetch the data from the database on a background thread paired with a CursorAdapter. The CursorLoader automatically registers with the database to be notified of changes. You then implement the LoaderManager callbacks which tell you when the dataset changes and passes you an updated cursor. You then call swapCursor(cursor) on the CursorAdapter, passing it the new cursor and it notifies the ListView DataSetObserver that the dataset has changed. The ListView then queries the adapter to get the new values and refreshes the UI.

Check out this tutorial for some good example code: http://www.vogella.com/tutorials/AndroidSQLite/article.html


Solution 2:

I figured it out i had to make this global List<ReceiptItem> receiptItemList = new ArrayList<ReceiptItem>(); Also I would like to thank middleseatman for explaining some things, it really helped me.


Post a Comment for "NotifyDataSetChange Does Not Refresh ListView With Custom Adapter"