BoD / android-contentprovider-generator

A tool to generate Android ContentProviders.
GNU General Public License v3.0
619 stars 151 forks source link

Adding support for CursorLoader #91

Closed codeversed closed 8 years ago

codeversed commented 8 years ago

I have been playing around with the idea that the _Object_Selection class would have a method to return a CursorLoader.

Something like this:

public CursorLoader cursorLoader(Context context, String[] projection) {
   return new CursorLoader(context, *Object*Columns.CONTENT_URI, projection, sel(), args(), order()) {
        @Override
        public Cursor loadInBackground() {
             return new *Object*Cursor(super.loadInBackground());
        }
   };
}

I am personally stuck on how to get the AbstractSelection to come into effect. Would we need a _Object_CursorLoader that extends a _Object_AbstractCursorLoader?

It seems that adding that Edited code above to the selection class would work well but I am not sure if it is nessessary.

13rac1 commented 8 years ago

:+1:

Here is an example creating a CursorLoader using the existing generated code using the sample project:

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String[] projection = { PersonColumns._ID, PersonColumns.FIRST_NAME, 
        PersonColumns.LAST_NAME, PersonColumns.AGE };
    final PersonSelection ps = new PersonSelection();
    ps.id(2);

    return new CursorLoader(this, ps.uri(), projection, ps.sel(), ps.args(), ps.order());
}

I'm not sure if this is better as a documentation update or a new generated function?

crashoverdone commented 8 years ago

Hi, i've been trying to use this generator in my project and i've done everything the right way. But i'm getting empty cursor on onLoadFinished. I' m creating the loader as above but no results. Any help advices?

Thanks in advance

Forget it...newbie bad forgetting to populate the DB looool. But thanks any how

BoD commented 8 years ago

Maybe if we can see your code that would help us help you.

crashoverdone commented 8 years ago

My code its fine. I'm using a sync service to get the data from a server to populate the DB and i forgot to call the sync adapter in main activity. Now its working fine. Newbie mistake.

And congrats for the nice work. this generator saved me hours of implementation.

Keep up the good work.

Thanks for the quick reply.

BoD commented 8 years ago

You're welcome, and thanks 😊

BoD commented 8 years ago

In b7be6a0, I added a getCursorLoader() method in Selection objects :) This will be in version 1.10.0.