简体   繁体   English

尝试在列表视图的末尾加载更多项目

[英]attempting to load more items at the end of listview

I am attempting to load more items at the end of listview. 我试图在列表视图的末尾加载更多项目。 upon scolling to the end of the listview only the progressbar is shown but more items is never added to the listview. 倾斜到列表视图的末尾时,仅显示进度条,但永远不会将更多项目添加到列表视图。

CustomAdapter adapter; //initialize adapter

@Override
    protected Integer doInBackground(Void... params) {
        return this.parseData();
    }

//called in onpost execute //在onpost执行中调用

adapter=new CustomAdapter(c,spacecrafts);
            lv.setAdapter(adapter);
lv.setOnScrollListener(new AbsListView.OnScrollListener() {

                public void onScrollStateChanged(AbsListView view, int scrollState) {

                }

                public void onScroll(AbsListView view, int firstVisibleItem,
                                     int visibleItemCount, int totalItemCount) {

                    if(firstVisibleItem+visibleItemCount == totalItemCount && totalItemCount!=0)
                    {
                        if(flag_loading == false)
                        {
                            flag_loading = true;

                            lv.setAdapter(adapter);
                            expand = expand + 5;

                        }
                    }
                }
            });

Please what could be wrong 请可能出了什么问题

不要清除您的列表,然后尝试。

spacecrafts.clear();

Try initialize the Adapter and ArrayList in your class body like bellow: 尝试像下面这样在类体中初始化Adapter和ArrayList:

ArrayList<Spacecraft> spacecrafts = new ArrayList<Spacecraft>();
CustomAdapter adapter = new CustomAdapter(spacecrafts);

Then call this code inside onCreate method 然后在onCreate方法中调用此代码

lv.setAdapter(adapter);

And after that when you added new items to the list you can notify the adapter by calling: 然后,当您将新项目添加到列表中时,可以通过调用以下命令通知适配器:

adapter.notifyDataSetChanged();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM