Search code examples
androidarraylistbaseadapter

How to limit an array list to 10 and display next 10 items on click of more


I am adding all the items in arrayList, now I want to display only 10 items in my recycler view and click of more 10 more and so on. I want to use same arrayList.


Solution

  • you can handle it by yourself in getCount() method.
    you can put a integer in your adapter class and by each click on more button increase it 1.

    int num = 1;
    

    on more button click:

    if((adapter.num)*10 < arrayList.size()) 
       adapter.num = adapter.num +1;
    

    and in getCount() method:

     @Override
    public int getCount() {
        if(num*10 > arrayList.size()){
            return arrayList.size();
        }else{
           return num*10; 
        }
    }