【发布时间】:2016-04-18 18:12:23
【问题描述】:
我尝试使用 notifyDataSetChanged() 刷新我的列表视图,但这标记为红色。我使用 ListView 之类的扩展适配器,因此 notifyDataSetChaned 它应该可以工作,但不然。
下面是我的声明ListView和ArrayList。
ListView listview;
ArrayList<ListData> myList = new ArrayList<>();
我是这样设置我的列表的:
listview = (ListView) findViewById(R.id.listView);
listview.setAdapter(new MyBaseAdapter(this, myList));
我也使用 setOnScrollListener,我希望我的列表视图在 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) {
}
});
【问题讨论】:
-
也许你应该检查你导入的包名是你的扩展列表视图。
标签: java android listview arraylist notifydatasetchanged