我有一个使用ListView
. 我创建了一个扩展类RemoteViewsService
:
public class AppWidgetService extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
return (new AppWidgetListFactory(this.getApplicationContext(), intent));
}
}
在我的AppWidgetProvider
中,我为小部件的每个实例(对于每个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);
}
的构造函数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);
}
现在的问题是,该fillInList
方法被调用的频率与小部件的实例一样频繁,但该onGetViewFactory
方法只被调用一次。这会导致所有小部件显示相同的数据。
我怎样才能解决这个问题?