【问题标题】:adding listview footer when listview scroll reaches the end当列表视图滚动到达末尾时添加列表视图页脚
【发布时间】:2017-01-28 10:15:00
【问题描述】:

我需要动态地在滚动视图到达末尾时添加或删除页脚。在某些时候我还需要它是可见的,而在其他时候我需要它是不可见的,因为我无法改变可见性还有其他方法吗。

我有一个像这样的滚动监听器

  listViewComments.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
                if (i == AbsListView.OnScrollListener.SCROLL_STATE_IDLE
                        && (listViewComments.getLastVisiblePosition() - listViewComments.getHeaderViewsCount() -
                        listViewComments.getFooterViewsCount()) >= (commentAdapter.getCount() - 1)) {
                   // removing or adding footer
                }
            }

当我这样做时,即使我调用该函数一次,它也会导致页脚闪烁,有时当我滚动它时,它会进入我的列表视图项目的中间。

【问题讨论】:

标签: android listview scroll footer


【解决方案1】:

您可以添加页脚视图:

listViewComments.addFooterView(yourFooterView);

你可以删除它:

listViewComments.removeFooterView(yourFooterView);

别忘了先放大你的页脚视图:

View yourFooterView = getLayoutInflater().inflate(R.layout.yourFooterXML, null);

【讨论】:

  • 是的,我在代码中的注释位置这样做了,但它闪烁
猜你喜欢
  • 1970-01-01
  • 2021-06-05
  • 1970-01-01
  • 2017-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-16
  • 1970-01-01
相关资源
最近更新 更多