Skip to content Skip to sidebar Skip to footer

Refresh A Simplecursoradapter After Performing Work On A Non-ui Thread

I'm trying to call .notifyDataSetChange() on a SimpleCursorAdapter displayed in a ListView from an XML-parsing non-UI thread and can't for the life of me figure out how. I've searc

Solution 1:

No need to create a new adapter...

.notifyDataSetChanged() should be called only in case the data rows actually changed (inserted or deleted rows), in case you just updated the values on rows a simple call to requery() on your cursor should be enough:

adapter.getCursor().requery();

Edit: by your comment I see that you have in fact a compilation problem...

You must declare the adapter as a class member (before/after mHandler declare it: private SimpleCursorAdapter adapter)

Then when you initialize it, replace

SimpleCursorAdapter adapter = newSimpleCursorAdapter(this,
    R.layout.directory_people_item, mCursor,
    new String[]{
        //snipnewint[]{
        //snip
); 

with:

adapter = newSimpleCursorAdapter(this,
    R.layout.directory_people_item, mCursor,
    new String[]{
        //snipnewint[]{
        //snip
); 

Solution 2:

Create a new adapter when the query is finished and set it your listview to give a general idea below is an example of gridview change it accordingly to suit your needs

globalAdapter = newGridImageAdapter(getApplicationContext());
globalAdapter.notifyDataSetChanged();
grid.setAdapter(globalAdapter);
grid.invalidateViews();

Post a Comment for "Refresh A Simplecursoradapter After Performing Work On A Non-ui Thread"