简体   繁体   中英

Android : Add Load more items in Horizontal listview

I am using horizontal list view and adding dynamic data into this, but I want to add an item when the scroll reached to the right most item in the listview . How can I get that scroll reached to the right most position?

Implement an onScrollListener to your listview, and fetch data through onScroll() method. There are many libraries for doing this easily. The following is a vertical listview example, but you can always change it to Horizontal and modify the code according to your needs.

https://github.com/shontauro/android-pulltorefresh-and-loadmore

In order to do that, you have to mock the size of the list ruled by your adapter. For example, if the list is called myList, its size is myList.size(), you will have to do something like: myList.add(mockelemnt).

Now that you have mocked the last element, what you may do is to handle it on your adapter method getView():

@Override
   public View getView(int position, View convertView, ViewGroup parent){
        if (oistion < myList.size(){
           //work with conventional view
        }else if (postion == myList.size()){
           //work with addMore view
      }

}

Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM