chiranjib
chiranjib

Reputation: 5308

Kindly provide the source code to determine the last item in the ListView

I am trying to implementing pagination in Android. Currently I am displaying in ListView , a list of 10 items where the data for the list items exist in the database.

Each list item contains an thumbnail Image Url , a text data

I have the following requirement. i> When the user scrolls to the 10 th list item , I am calling a webservice method of the server to fetch the next set of records.

My question is how can I determine when the user scrolls to the 10 th list item , what kind of validation can I make.

Kindly provide me the sample source code.

Warm Regards,

CB

Upvotes: 1

Views: 1112

Answers (1)

AjOnFire
AjOnFire

Reputation: 2878

If you want to fetch the next set of records when 10th item is visible on the list then write a condition in OnScrollListener similar to this...

mListView.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)
        {
            if(view.getLastVisiblePosition() == 10)
            {
                // do operation to retrieve other data into listview
            }
        }
    });

Upvotes: 2

Related Questions