The situation:
I have an activity with a spinner and a list with a BaseAdapter.
The list is loaded once, and shows correctly... But when I click on the spinner to change the underlying data and call adapter.notifyDataSetChanged(); the list doesn't refresh.
By this I mean that the data is changed and the adapter has the right data, it's just that the listView doesn't change the view.
How to force the listViews to show the right data?
Try adapter.notifyDataSetInvalidated(); as well as adapter.notifyDataSetChanged();
EDIT:
Clear your ArrayList or whatever you're using before you add more items with something like .clear(); and then add the new items and call adapter.notifyDataSetChanged();
Try
myListView.invalidateViews();
Related
It's easy to remove, add and insert an item from the listview adapter object, but I don't think I see a direct method to update an item in the listview adapter. Obviously, I could simply replace via remove/add, but I want to make sure I'm not missing something obvious.
Right now, I'm simply updating the underlying Item Array and refresh the entire listview by recreating/assigning the adapter (probably also not very elegant).
I hope the question is clear enough.
If you are using ArrayList in adapter class for update In ArrayList there is method called set() which update the item in arraylist after updation call notifyItemchanged() which update an item in listview
Check this link
im trying to create a feed like instagram. When the user reaches the bottom of the listview more pics should be added to the listview. Is there a way to add more to the listview with out calling notifyDataSetChanged() because it causes the listview to flicker.
Try creating a new Adapter or re-initializing the Adapter being used with added data then set that Adapter to the ListView.
Then use setSelection(int position) to move to the bottom of the ListView.
I use below code to update listview.
setListAdapter(MyAdapter);
MyAdapter.notifyDataSetChanged();
getListView().setEmptyView(empty);
But each time update, the list always show top one.
I want to let it only update data, but not focus on top.
How to do it?
Use a ArrayAdapter backed by an ArrayList. To change the data, just update the data in the list and call
MyAdapter.notifyDataSetChanged().
Although you can call notifyDataSetChanged() on SimpleAdapter too.
You need to add listview.setSelection(your_collection.size());. This will make the last item in the ListView as selected when you refresh the ListView. Also call this after refereshing the ListView.
The tab activity queries the database and binds the result to the list view.
The problems is when i clicked on the delete button, it works but the list view did not refresh.
the things i've tried:
adapter.notifyDataSetChanged();
adapter.notifyDataSetInvalidated();
listview.invalidateViews();
listview.setAdapter(adapter);
so far none is working, i have to click another tab (tab1) then click back (tab2) to refresh it.
Any ideas?
Note sure about the way you are using to delete. I think you are manipulating ListView directly. You have to use remove() method of adapter. In fact you have to manipulate the contents of the list through the adapter.
You should use this on delete button click:
((EfficientAdapter)listview.getAdapter()).notifyDataSetChanged();
where EfficientAdapter is your Adapter class.
Hope this will work for you...:)
I have a listview that switches between a few custom lists. I press a button to toggle between the different adapters in my listview but it jumps to the top of the listview. Is there a way I can stay in the same position on the screen as I switch between lists?
don't use set adapter to update content , use notifyDatasetChanged istead
if(listView.getAdapter()==null)
listView.setAdapter(myAdapter);
else{
//update the adapter data
myAdapter.notifyDatasetChanged();
}
that should work
Use any of these 2:
1. Call getListView().setSelection(int iIndex);
2. Call getListView().smoothScrollToPosition();
Kindly let me know, if any of these works.