Multiple bootloaders with LoaderManager without getting the correct bootloader

I have two loaders, one to populate the data returned by the link, up to 2 TextViews, and the other to populate ListView. How can I make sure that the correct bootloader is loading for every situation? I get an error in where the first loader ( WR_VIEWcase) does not seem to be created or loaded, so onLoadFinished()it returns “No such error with column detection” because it refers to the second loader that does not work Calling this column.

In my method, onCreateI configured the adapter to present the list:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.workouts_options);

    String[] uiBindFrom = { ExerciseTable.COLUMN_NAME };
    int[] uiBindTo = { R.id.text1 };

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(
        getApplicationContext(), 
        R.layout.exercises_row, 
        null, 
        uiBindFrom, 
        uiBindTo,
        CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);    

    final ListView lv = (ListView) findViewById(android.R.id.list);

    lv.setAdapter(adapter);
    lv.setEmptyView(findViewById(android.R.id.empty));
    lv.setClickable(true);
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
        }
    });

    getSupportLoaderManager().initLoader(WR_VIEW, null, this);
    getSupportLoaderManager().initLoader(EXERCISE_VIEW, null, this);
}

Create my 2 different CursorLoaders:

    public Loader<Cursor> onCreateLoader(int id, Bundle args) {         
        switch(id) {
            case WR_VIEW:
                String[] projection = { WorkoutRoutineTable.COLUMN_ID, WorkoutRoutineTable.COLUMN_NAME, WorkoutRoutineTable.COLUMN_DESCRIPTION };    
                return new CursorLoader(this, Workouts.buildWorkoutIdUri(""+mRowId), projection, null, null, null);
            default:
                String[] columns = {ExercisesColumns.NAME, WRExercisesColumns.COLUMN_ID };          
                return new CursorLoader(this, Workouts.buildWorkoutIdExerciseUri(""+mRowId), columns, null, null, null);
        }
    }

Bind the data to mine TextViewshere and swapCursorfor ListView:

public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    int id = loader.getId();
    switch(id) {
        case WR_VIEW: 
            if (cursor != null && cursor.moveToFirst()) {
                mNameText.setText(cursor.getString(cursor.getColumnIndexOrThrow(WorkoutRoutineTable.COLUMN_NAME)));
                mDescriptionText.setText(cursor.getString(cursor.getColumnIndexOrThrow(WorkoutRoutineTable.COLUMN_DESCRIPTION)));

                getSupportActionBar().setTitle(mNameText.getText());
                if (!TextUtils.isEmpty(mDescriptionText.getText())) {
                    getSupportActionBar().setSubtitle(mDescriptionText.getText());
                }
                cursor.close(); 
            }
        default:
            adapter.swapCursor(cursor);
        }
    }

Bootloader Reset:

public void onLoaderReset(Loader<Cursor> loader) {
    int id = loader.getId();
    switch(id) {
        case WR_VIEW: 
            break;
        default:
            adapter.swapCursor(null);
            break;
    }
}
+5
1

onLoadFinished() break WR_VIEW, , . (, onCreateLoader )

+5

All Articles