mercredi 2 septembre 2015

Android cursor loader SQLite with "load more" function

I'm trying to do some app which should gets some info from network, caching it at SQLite DB and when shows it on ListView.

The question is: how i can implement loadMore function with observing SQLite data changed? I know that android have CursorLoader for this purposes, but how i can tell him, that not i want get from DB only 10/20/30/etc first items? Where i should store current last id?

Now my code get all data of SQLite table without pagination:

@Override
public Loader onCreateLoader(int loaderID, Bundle arg1) {       
    return new CursorLoader(
            this, 
            ContractClass.Classes.CONTENT_URI, 
            ContractClass.Classes.DEFAULT_PROJECTION, 
            null, 
            null,  
            null); 
}

@Override
public void onLoadFinished(Loader loader, Cursor newData) {     
    mAdapter.swapCursor(newData);
}

@Override
public void onLoaderReset(Loader loader) {
    mAdapter.swapCursor(null);
}

Aucun commentaire:

Enregistrer un commentaire