I am using successfully OrmLite in my Android apps. I am moving my apps to the new CursorLoader logic and I would like to know how to use Ormlite with a CursorLoader without to have a ContentProvider.
Is't possible?
I think the best solution will be implement subclass for CursorLoader, and in loadInBackground() get and return cursor from ORM. In my case it was something like this
@Override
public Cursor loadInBackground() {
...
Dao<Account, String> dao = mHelper.getDao();
QueryBuilder<Account, String> qb = dao.queryBuilder();
CloseableIterator<Account> iterator = dao.iterator(qb.prepare());
try {
AndroidDatabaseResults results =
(AndroidDatabaseResults)iterator.getRawResults();
cursor = results.getRawCursor();
}
catch(Exception ex){
ex.printStackTrace();
}
...
return cursor;
}
Than you can use this Loader just as other loaders. You can look at full example with custom AsyncTaskLoader here: Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With