簡體   English   中英

當列表視圖滾動到達末尾時添加列表視圖頁腳

[英]adding listview footer when listview scroll reaches the end

我需要動態頁腳,可以在滾動視圖到達末尾時添加或刪除。 在某些時候我還需要它是可見的,而在其他時候我需要它是不可見的,因為我無法改變可見性,還有其他方法。

我有一個像這樣的滾動監聽器

  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
                }
            }

當我這樣做時,即使我調用該函數一次,它也會導致頁腳閃爍,有時當我滾動它時它會進入我的列表視圖項目的中間。

您可以添加頁腳視圖:

listViewComments.addFooterView(yourFooterView);

你可以刪除它:

listViewComments.removeFooterView(yourFooterView);

不要忘記先增加頁腳視圖:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM