Justin Babu
Justin Babu

Reputation: 25

adding listview footer when listview scroll reaches the end

I need to dynamically footer which can be add or remove when ever scrollview reaches the end. at some point I also need it to be visible and at other times I need it to be invisible , since I can't change visibility is there any other way.

I am having an on scroll listener like this

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

when I do like this it results in flickering of the footer even if I am calling the function once, sometimes when I scroll it gets in the middle of my listview items.

Upvotes: 1

Views: 257

Answers (1)

Lubomir Babev
Lubomir Babev

Reputation: 1908

You can add your footer view :

listViewComments.addFooterView(yourFooterView);

and you can remove it :

listViewComments.removeFooterView(yourFooterView);

Don't forget to inflate your footer view first :

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

Upvotes: 1

Related Questions