简体   繁体   English

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

[英]setOnScrollListener() of Expandable Listview under scrollview

I am using around 27 Expandable Listview(That scroll inside Scrollview, not the one that has parent, child relation) inside Scrollview(One is visible at a time, after selecting some text). 我正在使用大约27个Expandable Listview(在Scrollview中滚动,而不是具有父,子关系的滚动)(在选择一些文本后一次可见)。 I want to add load more on this, while user reached to last item while scrolling listview. 我想在此上增加负载,同时用户在滚动列表视图时到达最后一项。 But setOnScrollListener() return me last item instantly while loading data instead of Scrolling. 但是setOnScrollListener()会在加载数据而不是滚动时立即返回我的最后一项。 Please suggest some way to use load more in this condition. 请提出一些在这种情况下更多使用负载的方法。

 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");

                          }
                        }

                    }
                });

If you want to use setOnScrollListener() of Expandable Listview under scrollview, You can't use it inside scrollview, but you may have another solution as i have used and fixed my problem. 如果要在scrollview下使用Expandable Listview的setOnScrollListener(),则不能在scrollview中使用它,但是您可能有另一种解决方案,因为我已经使用并解决了我的问题。

you may simply remove your Scrollview, and header layout above listview, and keep listview only in layout file. 您可以简单地删除Scrollview和listview上方的标题布局,并将listview仅保留在布局文件中。 and then use your headerView as a listview headerView. 然后将您的headerView用作listview headerView。

create another layout as a layout_headerview.xml and put your header content in this file, 创建另一个布局作为layout_headerview.xml并将标题内容放入此文件中,

finally set them as a headerView of listview, 最后将它们设置为listview的headerView,

write below code in your onCreate() method. 在您的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