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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:51:10+00:00 2026-05-27T20:51:10+00:00

I have a simple contentProvider, a layout with a ListView and a button for

  • 0

I have a simple contentProvider, a layout with a ListView and a button for adding Items in content Provider and a CursorLoader. The android.content.Loader, D reference states that

The Loader will monitor for changes to the data, and report them to
you through new calls here. You should not monitor the data yourself.
For example, if the data is a Cursor and you place it in a
CursorAdapter, use the CursorAdapter(android.content.Context,
android.database.Cursor, int) constructor without passing in either
FLAG_AUTO_REQUERY or FLAG_REGISTER_CONTENT_OBSERVER (that is, use 0
for the flags argument). This prevents the CursorAdapter from doing
its own observing of the Cursor, which is not needed since when a
change happens you will get a new Cursor throw another call here.

But the Log.info line in the onLoadFinished method was not executed and listView didn’t refreshed. Here is my (simple) code:

public class HomeActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor>{
static final String TAG = "HomeActivity";
SimpleCursorAdapter adapter;
ListView listAnnunciVicini;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    listAnnunciVicini = (ListView) findViewById(R.id.lista_annunci_vicini);

    adapter = new SimpleCursorAdapter(this, R.layout.list_item, null, 
            new String[] {
                    ContentDescriptor.Annunci.Cols.ID, 
                    ContentDescriptor.Annunci.Cols.TITOLO, 
                    ContentDescriptor.Annunci.Cols.DESCRIZIONE 
            }, new int[] { 
                    R.id.list_annunci_item_id_annuncio, 
                    R.id.list_annunci_item_titolo_annuncio,
                    R.id.list_annunci_item_descrizione_annuncio
            }, 0);
    listAnnunciVicini.setAdapter(adapter);

    // Prepare the loader. Either re-connect with an existing one,
    // or start a new one.
    getSupportLoaderManager().initLoader(0, null, this).forceLoad();
}

public void addRandomItem(View sender) {
    ContentValues dataToAdd = new ContentValues();
    dataToAdd.put(ContentDescriptor.Annunci.Cols.TITOLO, "Titolo");
    dataToAdd.put(ContentDescriptor.Annunci.Cols.DESCRIZIONE, "Lorem ipsum dolor sit amet.");
    this.getContentResolver().insert(ContentDescriptor.Annunci.CONTENT_URI, dataToAdd);
}

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    // creating a Cursor for the data being displayed.
    String[] proiezione = new String[] {ContentDescriptor.Annunci.Cols.ID, ContentDescriptor.Annunci.Cols.TITOLO, ContentDescriptor.Annunci.Cols.DESCRIZIONE };
    
    CursorLoader cl = new CursorLoader(this, ContentDescriptor.Annunci.CONTENT_URI, proiezione, null, null, null);
    return cl;
}

public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    // Swap the new cursor in.  (The framework will take care of closing the
    // old cursor once we return.)
    adapter.swapCursor(data);
    Log.i(TAG, "I dati sono stati ricaricati");
}

public void onLoaderReset(Loader<Cursor> loader) {
    // This is called when the last Cursor provided to onLoadFinished()
    // above is about to be closed.  We need to make sure we are no
    // longer using it.
    adapter.swapCursor(null);
}
}

Any suggestion?

  • 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-05-27T20:51:11+00:00Added an answer on May 27, 2026 at 8:51 pm

    AFAIK, you need to implement notification yourself in ContentProvider. For this, add something like getContext().getContentResolver().notifyChange(uri, null); to insert,update and delete method of ContentProvider and invoke.setNotificationUri(getContext().getContentResolver(), uri) on your Cursor in queryas described in official documentation. Here you can find the whole picture.

    Note: You should not close the cursor (cursor.close()) in order to get
    notifications about the changes.

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

Sidebar

Related Questions

I have simple button: <button type=button id=somebutton value=start>blah</button> in jQuery, on the bind('click, function(){....
I have simple registration form. Once all information entered, user click submit button and
So I created a simple content provider, but I've got an error : Failed
I have simple mxml code <mx:DataGrid id=DGG editable=true> <mx:dataProvider> <mx:Object scheduledDate=4/1/2006/> </mx:dataProvider> </mx:DataGrid> <mx:Button
Have simple Spring Security webapp with password encoding: <security:authentication-manager alias=authenticationManager> <security:authentication-provider user-service-ref=personService> <security:password-encoder hash=md5
I have simple regex \.*\ for me its says select everything between and ,
I have simple win service, that executes few tasks periodically. How should I pass
i have simple regular expression: ^123$ Matches are for example 123 1234 etc. How
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input

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.