Search code examples
androidsqlitecursorcursor-positionandroid-cursoradapter

android change cursor position in cursor adapter to increse or decrease rows


I need to implement CursorAdapter, where i need to filter out certain rows at a time.

For ex: first showing 1-5, then 5-10.

I have managed getCount() as per it, but just by changing cursor position it is not working.

I need to know how these rows get the position, or how to advance the cursor that is provided as parameter in newView() and bindView().

P.S: I know about limit and paging and offset, but not want to fetch query every time


Solution

  • Hey in your adapter override these methods as below. You can change the page by changing the presentPage and notifiy the adpater

     int numOfItemsPerPage=5,presentPage=0;
     public int getCount() {
       return (list.size()>= numOfItemsPerPage) ?list.size():numOfItemsPerPage;
     }
    
     public Object getItem(int position) {
           if(list.size()>= numOfItemsPerPage)
           {
              position= (numOfItemsPerPage * presentPage)+position;
           }
           return list.get(position);
     }