adapter.notifyDataSetChanged() not refreshing my TimelineActivity

Resources » Forums » Android - Learning Android book > adapter.notifyDataSetChanged() not refreshing my Tim...
July 31, 2011 6:24:53 AM PDT (one year ago). Seen 2,852 times. One reply.
Photo Adithya Narayan
Engineer
SGS
Member since Jul 19, 2011
Forum Posts: 23
Hi,

When my Updater Service is broadcasting a specified intent, my Broadcast Receiver associated with the Timeline Activity is receiving it. Now, the problem is after cursor.requery() the next statement timelineAdapter.notifyDataSetChanged() is having no effect on the Activity where timelineAdapter is the adapter which is responsible for mapping the data from database table columns to the ListView's attributes.

I was under the impression that when timelineAdapter.notifyDataSetChanged() is called automatically the TimelineActivity.onResume() method should be called. Am i right ? Or we need to call TimelineActivity.onResume() explicitly in order to refresh the Activity and the UI ?




September 4, 2011 3:42:38 AM PDT (one year ago)
Photo Vivek Ragunathan
NA
Member since Sep 4, 2011
Forum Posts: 9
I too had the same problem. Ideally the list should get refreshed on requery + notifyDataChanged but it does not work. Not sure why. So I used the following method to make it work:-

private void refresh()
{
cursor = getYamba().getStatusData().getStatusupdates();
startManagingCursor(cursor);
cursorAdapter = new TimelineAdapter(this, cursor);
listTimeline.setAdapter(cursorAdapter);
}

class TimelineReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
// cursor.requery();
// cursorAdapter.notifyDataSetChanged();
cursor.close();
refresh();
Log.i(LogTag, String.format("TimelineReceiver.onReceive(%s)", intent.getAction()));
}
}

Hope that helps.