开发者

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 questi开发者_开发问答on 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


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
            }
        }
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜