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:
public class UpdateWidgetService extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
return new ListProvider(this.getApplicationContext(), intent);
}
}
And use the service class instead of the RemoteViewFactory directly:
for (int i = 0; i < appWidgetIds.length; ++i) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
Intent serviceIntent = new Intent(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"