I am trying to implement a DataListFragment with an adapter that uses the Loader from Commonsware. This bootloader uses SQLiteDatabase directly and does not require the use of ContentProviders.
Android downloader links: "While bootloaders are active, they need to control the source of their data and provide new results when content changes."
In my implementation of SQLiteCursor (below) this does not happen. OnLoadFinished()called once and that he. Presumably, one could insert calls Loader.onContentChanged()where the base database will be modified, but overall the database code class is not aware of loaders, so I'm not sure of the best way to implement this.
Does anyone have any tips on how to “know the bootloader data”, or should I wrap the database stuff as a ContentProvider and use CursorLoader instead?
import com.commonsware.cwac.loaderex.SQLiteCursorLoader;
public class DataListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>{
protected DataListAdapter mAdapter;
public SQLiteDatabase mSqlDb;
private static final int LOADER_ID = 1;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
int rowlayoutID = getArguments().getInt("rowLayoutID");
mAdapter = new DataListAdapter(getActivity(),rowlayoutID, null , 0);
setListAdapter(mAdapter);
LoaderManager lm = getLoaderManager();
lm.initLoader(LOADER_ID, null, this);
}
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
String sql="SELECT * FROM "+TABLE_NAME+";";
String[] params = null;
SQLiteCursorLoader CursorLoader = new SQLiteCursorLoader(getActivity(), mSqlDb, sql, params);
return CursorLoader;
}
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
mAdapter.swapCursor(data);
if (isResumed()) { setListShown(true);}
else { setListShownNoAnimation(true); }
}
public void onLoaderReset(Loader<Cursor> loader) {
mAdapter.swapCursor(null);
}
source
share