Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8238735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:54:51+00:00 2026-06-07T19:54:51+00:00

I have two loaders, one to populate bind returned data to 2 TextViews and

  • 0

I have two loaders, one to populate bind returned data to 2 TextViews and another to populate a ListView. How do I make sure the correct loader loads for each situation? I am getting an error in the where first loader (WR_VIEW case) doesn’t seem to be created or loading so in the onLoadFinished() it returns a “No such column found error” because it is accessing the second loader which doesn’t call that column.

Here in my onCreate method I set up the adapter for the list view:

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 data to my TextViews here and swapCursor for the 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);
        }
    }

Resetting the Loader:

public void onLoaderReset(Loader<Cursor> loader) {
    int id = loader.getId();
    switch(id) {
        case WR_VIEW: 
            break;
        default:
            adapter.swapCursor(null);
            break;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:54:53+00:00Added an answer on June 7, 2026 at 7:54 pm

    In your onLoadFinished() you don’t have a break after WR_VIEW case, so the default clause is getting run as well, passing the wrong cursor to your adapter. (onCreateLoader seems to have a similar issue as well)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity which uses two Loaders. Each of them returns different type
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two classes (MVC view model) which inherits from one abstract base class.
I have two classes, call them A and B. They both contain a Loader
I have two function, one function is a reload function that does a ajax
in eclipse plugin i have two plug-in which are used there own class loader
I have been trying to make my website performs well. One way that may
I have two app domains, one parent creating the child domain. In the child
I have two requirements, and im not sure is those things possible in AS3.
I have two custom QML elements for audio, one for playing music (and extends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.