如何使用 BaseAdapter 刷新我的 ListView

How can I refresh my ListView using BaseAdapter

我尝试使用 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) {

        }
    });

notifyDataSetChanged()BaseAdapter class 和 not[= 的方法23=] ListView class。因此,调用 listView.notifyDatasSetChanged();.

在逻辑上和语法上都是不正确的

将此行替换为

listView.getAdapter().notifyDataSetChanged();

祝一切顺利:)

定义一个适配器对象, MyBaseAdapter 适配器=new MyBaseAdapter(this, myList); adapter.notifyDataSetChanged();