CursorAdapter.swapCursor is not updated the first time

I have a ListActivity and use a CursorLoader to load data that is stored in the ContentProvider. I am using a custom class that extends CursorAdapter to display list items. In LoaderCallbacks onLoadFinished I have the following:

public void onLoadFinished(Loader<Cursor> loader, Cursor newCursor) {
   cursorAdapter.swapCursor(newCursor);
}

      

I have a custom layout for a ListActivity that includes a TextView with android:id="@android:id/empty"

.

The problem is that when the app is first opened when called, the swapCursor

ListView is not updated even though there is data in the ContentProvider. When I add a new item to the ListView, the list is updated as expected. However, if I comment out the TextView that displays plain text when no data is available, the application works as expected. The swapCursor call automatically updates the ListView accordingly.

Any thoughts as to why this is happening, or if there is a correct way to do it, as I believe that calling notifyDataSetChanged will not do the job as the update is not being done in a very specific case?

+3


source to share


1 answer


You are having this problem because it ListActivity

automatically sets an empty view (if available) to yours ListView

.

I suggest you try one of these:



  • Extend the action and then swapCursor

    call

    listView.setEmptyView(findViewById(android.R.id.empty);
    
          

  • Remove the empty view: android:visibility="gone"

    and after the swapCursor

    call

    findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
    
          

  • @ on Create a call listView.setEmptyView(null)

    and then swapCursor

    call

    listView.setEmptyView(findViewById(android.R.id.empty);
    
          

Not sure if all of them, but one of them will definitely work :)

+2


source







All Articles