繁体   English   中英

滚动视图下的可扩展列表视图的setOnScrollListener()

[英]setOnScrollListener() of Expandable Listview under scrollview

我正在使用大约27个Expandable Listview(在Scrollview中滚动,而不是具有父,子关系的滚动)(在选择一些文本后一次可见)。 我想在此上增加负载,同时用户在滚动列表视图时到达最后一项。 但是setOnScrollListener()会在加载数据而不是滚动时立即返回我的最后一项。 请提出一些在这种情况下更多使用负载的方法。

 listViewsSearchResults[i].setOnScrollListener(new AbsListView.OnScrollListener() {

                    @Override
                    public void onScrollStateChanged(AbsListView view, int scrollState) {

                    }

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

                        if (firstVisibleItem + visibleItemCount == totalItemCount && totalItemCount != 0) {

                            //call API
                            Log.d("ListView ", alphabets[finalI] + " Hit API");

                          }
                        }

                    }
                });

如果要在scrollview下使用Expandable Listview的setOnScrollListener(),则不能在scrollview中使用它,但是您可能有另一种解决方案,因为我已经使用并解决了我的问题。

您可以简单地删除Scrollview和listview上方的标题布局,并将listview仅保留在布局文件中。 然后将您的headerView用作listview headerView。

创建另一个布局作为layout_headerview.xml并将标题内容放入此文件中,

最后将它们设置为listview的headerView,

在您的onCreate()方法中编写以下代码。

LayoutInflater layoutInflater;
View headerView;
layoutInflater = LayoutInflater.from(this);
headerView = layoutInflater.inflate(R.layout.layout_headerview, null);

//add it in your listview
listView.addHeaderView(headerView);

// to access headerView widgets you may use below,
iv_overlay = (ImageView) headerView.findViewById(R.id.iv_overlay);

暂无
暂无

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

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