I have an appwidget which uses ListView
.
I have created a class that extends RemoteViewsService
:
public class AppWidgetService extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
return (new AppWidgetListFactory(this.getApplicationContext(), intent));
}
}
In my AppWidgetProvider
, I call the following method for each instance of the widget (for each appWidgetId
):
private static void fillInList(RemoteViews widget, Context context, int appWidgetId) {
Intent intent = new Intent(context, AppWidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
widget.setRemoteAdapter(R.id.appwidget_listview, intent);
}
The constructor of the AppWidgetListFactory
public AppWidgetListFactory(Context context, Intent intent) {
this.context = context;
appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
System.out.println("New TVAPWLF for: " + appWidgetId);
trains = WidgetData.getInstance().widgetMap.get(appWidgetId);
}
Now the problem is, that the fillInList
method gets called just as often as there are instances of the widget, but the onGetViewFactory
method only gets called once. This results in all the widgets showing the same data.
How can I fix this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…