Skip to content Skip to sidebar Skip to footer

Listview In Widget Does Not Update

I want to update a ListView in a widget from a service. For this I have this code in my service: Intent intent = new Intent(ctx, ListProvider.class); intent.putExtra(AppWidgetManag

Solution 1:

Use a service to update the remote adapter:

publicclassUpdateWidgetServiceextendsRemoteViewsService {
    @Overridepublic RemoteViewsFactory onGetViewFactory(Intent intent) {
        returnnewListProvider(this.getApplicationContext(), intent);
    }
}

And use the service class instead of the RemoteViewFactory directly:

for (inti=0; i < appWidgetIds.length; ++i) {
    RemoteViewsremoteViews=newRemoteViews(context.getPackageName(), R.layout.widget_layout);

    IntentserviceIntent=newIntent(context, UpdateWidgetService.class);
    serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
    serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(appWidgetIds[i], R.id.stackWidgetView, serviceIntent);
    remoteViews.setEmptyView(R.id.stackWidgetView, R.id.no_data_imageview);
    appWidgetManager.updateAppWidget(appWidgetIds[i], remoteViews);
}

Never tested it in a listView.

Post a Comment for "Listview In Widget Does Not Update"