【问题标题】:Listview visible child elementListview 可见子元素
【发布时间】:2013-07-16 09:16:42
【问题描述】:

在我的应用程序中,我使用了"Listview"。我想要的是我必须得到count of the visible child
例如,如果我在我的设备中加载该列表视图的第一双鞋 3 行,那么我必须在文本视图中显示"Showing 3 of 10",并且当用户滚动列表视图我必须根据滚动更新该文本视图..我尝试了很多,但我没有做到这一点..

我也试过了:

 int count=0;
for(int i = 0; i  <= listView.getLastVisiblePosition(); i++)
        {
            if(listView.getChildAt(i)!= null)
            {

                count++;  // saying that view that counts is the one that is not null, because sometimes you have partially visible items....
            }
        }

总是返回 0。请帮我解决这个问题。

【问题讨论】:

    标签: android listview


    【解决方案1】:

    我得到了答案....

    我实现了 onscroll 监听器..

    library_listview.setOnScrollListener(new OnScrollListener() {
    
                @Override
                public void onScrollStateChanged(AbsListView view, int scrollState) {
                    // TODO Auto-generated method stub
    
                }
    
                @Override
                public void onScroll(AbsListView view, int firstVisibleItem,
                        int visibleItemCount, int totalItemCount) {
                    // TODO Auto-generated method stub
                    firstVisibleItem = firstVisibleItem+1;
                    String vischild="Showing "+firstVisibleItem+" to "+visibleItemCount+" of "+totalItemCount+"";
                    visiblechild.setText(vischild);
    
                }
            });
    

    非常感谢..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-20
      • 1970-01-01
      相关资源
      最近更新 更多