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 8098429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:04:37+00:00 2026-06-05T22:04:37+00:00

So I have my MainDisplayActivity which implements both Activity and LoaderManager.LoaderCallbacks<Cursor> . Here I

  • 0

So I have my MainDisplayActivity which implements both Activity and LoaderManager.LoaderCallbacks<Cursor>. Here I have A ListView, which I fill with Agenda information that I get from my database using a ContentProvider. I also have a GridView which is a calendar. I have it set up when clicking a cell, that the agenda is updated with the day clicked. My problem is that when reusing the Loader I created in onCreate() inside of the setOnItemClickListener(), it does not refresh the information with the new cursor I am creating. I can just create a new Loader with another ID, and it works once, but once I click another day, it stops refreshing. The problem, lies in the cursor. How can I refresh a cursor from a Loader so I don’t have to keep creating a new Loader? Thanks in advance!

Initial call to create the Loader in onCreate() in My MainDisplayActivity class:

makeProviderBundle(new String[] {"_id, event_name, start_date, start_time, end_date, end_time, location"},
            "date(?) >= start_date and date(?) <= end_date", new String[]{getChosenDate(), getChosenDate()}, null);
    getLoaderManager().initLoader(0, myBundle, MainDisplayActivity.this);

    list.setAdapter(agendaAdapter);

These are the overridden methods from LoaderCallbacks<Cursor>

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Uri baseUri = SmartCalProvider.CONTENT_URI;
    return new CursorLoader(this, baseUri, args.getStringArray("projection"), 
            args.getString("selection"), args.getStringArray("selectionArgs"), args.getBoolean("sortOrder") ? args.getString("sortOrder") : null );
}



@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
    agendaAdapter.swapCursor(arg1);
}



@Override
public void onLoaderReset(Loader<Cursor> arg0) {
    //Not really sure how this works. Maybe I need to fix this here?
    agendaAdapter.swapCursor(null);

}

public void makeProviderBundle(String[] projection, String selection, String[] selectionArgs, String sortOrder){
    /*this is a convenience method to pass it arguments 
     * to pass into myBundle which in turn is passed 
     * into the Cursor loader to query the smartcal.db*/
    myBundle = new Bundle();
    myBundle.putStringArray("projection", projection);
    myBundle.putString("selection", selection);
    myBundle.putStringArray("selectionArgs", selectionArgs);
    if(sortOrder != null) myBundle.putString("sortOrder", sortOrder);
}

Any additional code needed please do not hesitate to ask. Thanks again for any help!

  • 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-05T22:04:38+00:00Added an answer on June 5, 2026 at 10:04 pm

    You just need to move your code around a little and call restartLoader. That is,

    1. When the user clicks a list item, you somehow change the private instance variable that is returned in getChosenDate() (I am being intentionally vague here because you didn’t specify what exactly getChosenDate() returns).

    2. Once the change is made, call getLoaderManager().restartLoader() on your Loader. Your old data will be discarded and restartLoader will trigger onCreateLoader to be called again. This time around, getChosenDate() will return a different value (depending on the list item that was clicked) and that should do it. Your onCreateLoader implementation should look something like this:

      @Override
      public Loader<Cursor> onCreateLoader(int id, Bundle args) {
          Uri baseUri = SmartCalProvider.CONTENT_URI;
      
          makeProviderBundle(
              new String[] { "_id, event_name, start_date, start_time, end_date, end_time, location" },
              "date(?) >= start_date and date(?) <= end_date", 
              new String[]{ getChosenDate(), getChosenDate() }, 
              null);
      
          return new CursorLoader(
                  this, 
                  baseUri, 
                  args.getStringArray("projection"), 
                  args.getString("selection"), 
                  args.getStringArray("selectionArgs"),    
                  args.getBoolean("sortOrder") ? args.getString("sortOrder") : null);
      }
      

    Let me know if that makes sense. 🙂

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

Sidebar

Related Questions

Have a network location that shows paths in the 8.3 short format. I need
Have data that has this kind of structure. Will be in ascending order by
Have data that has this kind of structure: $input = [ { animal: 'cat',
Have searched for the answer but no joy, so here goes... I'm working on
Have a simple one-off tasks which needs a progress bar. OpenSSL has a useful
have a help file which i have created in Notepad++ with the following syntax
Have a bunch of WCF REST services hosted on Azure that access a SQL
Have a look at one of my websites: moskah.com The problem is that it
Have a simple contact us XPage created. Have server side validation in place that
Have a really weird one here. The app has two targets, just to be

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.