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

  • Home
  • SEARCH
  • 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 8507185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:47:55+00:00 2026-06-11T02:47:55+00:00

I want to reflect data from various tables in a sqlite database at different

  • 0

I want to reflect data from various tables in a sqlite database at different times in a single ListView.

The initial query works fine, which goes like this:

  • I have a custom CursorAdapter class (AutoCursorAdapter extends CursorAdapter) which can display arbitrary data from a Cursor:
    • AutoCursorAdapter.newView() interrogates the cursor and constructs a view corresponding to the types of data in the columns.
    • AutoCursorAdapter.bindView() takes the data from the cursor and populates the view created in newView for each row of data in the cursor.
  • I also implement a loader in the owning Fragment as follows:

    public class MyFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor>{
    ...
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
             ...
             mListView = ((ListView) view.findViewById(R.id.listview));
             mAdapter = new AutoCursorAdapter(getActivity());
             mListView.setAdapter(mAdapter);
             return view;
         }
    
         public void onStart() {
            super.onStart();
            // Prepare the loader.  Either re-connect with an existing one,
            // or start a new one.
            LoaderManager lm = getLoaderManager();
            Bundle args = getArguments();
            lm.initLoader(LOADER_ID, args, this);
        }
    
        public Loader<Cursor> onCreateLoader(int id, Bundle args) {
            CursorLoader CursorLoader = new CursorLoader(getActivity());
            setupLoader(CursorLoader); //Sets the URI, projection etc. depending on app state
            return CursorLoader;
        }
    
        public void onLoaderReset(Loader<Cursor> loader) {
            mAdapter.swapCursor(null);
        }
    }
    

So far, so good. The data gets loaded on the initial run. Let’s say it pulls and displays data from table A using URI_A.

But now the question is: How do I deal with the case where I want to switch over to displaying data from table B using URI_B in response to a user action?

  • Can I do this with a single Loader instance?

    1. If so how? For instance CursorLoader.setUri() does not trigger a reload.
    2. If not, how do I manage multiple loader instances properly?
  • Is this an instance where Loaders perhaps aren’t the way to go?

Note: the question is not about reflected changes in the underlying DB in table A. This gets updated in the UI correctly already through the NotifyChange mechanism. This question is about changing the nature of the underlying query altogether.

  • 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-11T02:47:57+00:00Added an answer on June 11, 2026 at 2:47 am

    Can I do this with a single Loader instance?

    I would not recommend it. Loaders have enough state that trying to change them significantly like this may be troublesome, and having more than one loader is not that big of a deal when they all return the same data type (e.g., Cursor).

    If not, how do I manage multiple loader instances properly?

    Use different IDs for them (second parameter on initLoader()), and create the right Loader in onCreateLoader() based on ID.

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

Sidebar

Related Questions

I want to copy data from one text box to another in html automatically
I have three activities, say I have the data from ActivityA, and I want
I want to move full text catalogue for 1 database to a different location
Suppose I want to reflect exception in the log. Should I pass stack trace
I mean, I want the logger name to reflect the source.jsp file, no matter
Want to run javascript function from parent window in child window Example I have
Want to open firefox from terminal at linux with firebug enabled // Terminal $
I want to have a fix length mutable content shared data buffer and that
I need to clone some data from a master source in the ViewModel into
I have a SQL database and i am performing the following query on it.

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.