I am doing like a quote application that pulls the quotes from the database and I need to display quotes in a ViewPager.
I have created my CursorPagerAdapter which
MainActivity - add/modify:
String getSelection(){
if(null != mSearchKeyword && mSearchKeyword.getLength()>0) {
return QuoteContentProvider.COLUMN_AUTHOR + " LIKE '%" + mSearchKeyword + "%' OR " +
QuoteContentProvider.COLUMN_MESSAGE + " LIKE '%" + mSearchKeyword + "%'";
} else {
return null;
}
}
String mSearchKeyword = null;
public void search(String keyword) {
mSearchKeyword = keyword;
Log.d(MainActivity.TAG, "Search keyword: " + keyword);
getLoaderManager().restartLoader(-1, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
return new CursorLoader(this, QuoteContentProvider.CONTENT_URI, null, getSelection(), null, null);
}
Once the method search is fired, call getLoaderManager().restartLoader() on your Loader. Your old data will be discarded and restartLoader will trigger onCreateLoader to be called again.
Do not forget close old cursor after it is swapped