I tried refresh my listview using notifyDataSetChanged() but this is marked on red. I use ListView like extended Adapter so notifyDataSetChaned it should work but is otherwise.
Below is my declaration ListView and ArrayList.
ListView listview;
ArrayList<ListData> myList = new ArrayList<>();
I set up my list in this way:
listview = (ListView) findViewById(R.id.listView);
listview.setAdapter(new MyBaseAdapter(this, myList));
I use also setOnScrollListener and I want that my listview it refresh when SROLL_STATE = 0;
listview.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
int position = listview.getFirstVisiblePosition();
SCROLL_STATE = position;
if (SCROLL_STATE == 0) {
listview.notifyDataSetChanged(); // Here is a problem, because it's not work
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
notifyDataSetChanged()
is a method of the BaseAdapter class and not the ListView class. Hence, it is logically and syntactically incorrect to call listView.notifyDatasSetChanged();
.
Replace this line with
listView.getAdapter().notifyDataSetChanged();
All the best :)
Define a Adapter object, MyBaseAdapter adapter=new MyBaseAdapter(this, myList); adapter.notifyDataSetChanged();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.