I have a ListView with an adapter. I have only an ImageView-object on my ListViewItem. When I change the content of the Bitmaps in the ListViewItems, I always have to call adapter.notifyDataSetChanged()
. Otherwise the Bitmaps are not refreshed. I already tried myImageView.Invalidate()
on each ImageView in the Listview, but this doesn´t help.
Some Code for updating the ListViews:
runOnUiThread(new Runnable()
{
@Override
public void run()
{
Canvas myCanvas = rowItems.get(0).getCanvas();
// draw on canvas
adapter.notifyDataSetChanged();
}
});
Now my question: Is there an alternative to refresh the ListViews (in my case the content of the bitmaps) or do I have to call notifyDataSetChagend? Thanks!
The adapter needs to know that the data has changed in order to refresh itself so it's necessary to do so. The question is why you need an alternative in the first place!
However if you need it to be more performant you can notify the specific item got changed not the whole items by using RecyclerView.Adapter's notifyItemChanged (int position) and this is not available if you still using ListView.