0
votes

TASK: I want to display a list of ListView and when you select an item to display the list of dialogue and display it in a list of another element (parent and child elements)

  static class GroupCursorLoader extends CursorLoader {
    DB db;

    public GroupCursorLoader(Context context, DB db) {
        super(context);
        this.db = db;
    }

    @Override
    public Cursor loadInBackground() {
        Cursor cursor = db.getGroupAll();

        return cursor;
    }
}


static class DetailCursorLoader extends CursorLoader{
    DB db;

    public DetailCursorLoader(Context context, DB db) {
        super(context);
        this.db = db;
    }

    @Override
    public Cursor loadInBackground() {
        Cursor cursor;
        cursor = db.getDetailAll();

        return cursor;
    }
}

Now, The question is, how to handle the two Cursor?, i.e . written in the following methods

public Loader onCreateLoader(int id, Bundle args)

public void onLoadFinished(Loader loader, Cursor data)

public void onLoaderReset(Loader loader)

  @Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
   
    return return new GroupCursorLoader(this, mDB);
}

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    scAdapterForGroup.swapCursor(data);
}

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    Log.d(LOG, "onLoadReset");
}
1
you should write the content in english - Blackbelt
Ask your question at ru.stackoverflow.com - Jens

1 Answers

0
votes
    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
      if(id == GROUP_LOADER_ID) {
        return new GroupCursorLoader(this, mDB);       
      } else {
        return new DetailCursorLoader(this, mDB);
      }
    }

   @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
      if(loader instanceof GroupCursorLoader) {
        scAdapterForGroup.swapCursor(data);
      } else {
        scAdapterForDetails.swapCursor(data);
      }
   }

   @Override
   public void onLoaderReset(Loader<Cursor> loader) {
    Log.d(LOG, "onLoadReset");
   }

Answer question at ru.stackoverflow.com