それはonUpdate
が呼ばれるたびに、それは私が最初にTextView
を設定するときに、私はsharedprefsへのTextViewのテキストを保存し、その後、私は時に好みを得るので、私は何が使用SharedPreferencesで、ウィジェットの全てを更新することを私の理解であります私は更新する。そして私はfor
ループ内でこれをすべて行います。
は、ここに私のonUpdate
です:私のクラスMで
@Override
public void onUpdate(Context context, AppWidgetManager awm, int[] appWidgetIds){
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
int appWidgetId;
for (int i=0;i<appWidgetIds.length;i++){
appWidgetId = appWidgetIds[i];
String widgetLabel = pref.getString("label"+appWidgetId, "");
// I previously saved "widgetLabel" when I created the widget in my
// ConfigurationActivity
M.updateWidget(context, appWidgetId, widgetLabel);
// I put this in another class so it's more manageable.
}
}
:
public static void updateWidget(Context context, int appWidgetId, String widgetLabel){
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
RemoteViews updateViews;
int layoutId = R.layout.layout;
int viewId = R.id.layout;
updateViews = new RemoteViews(context.getPackageName(),
layoutId);
updateViews.setTextViewText(R.id.widgetlabel, widgetLabel);
editor.putString("label"+appWidgetId, widgetLabel);
editor.commit();
Intent intent = new Intent(context, ClickAction.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
updateViews.setOnClickPendingIntent(viewId, pendingIntent);
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, updateViews);
}
私はそれが理にかなって願っています。私が何かを工夫する必要があるかどうかを教えてください。
ありがとうございます!それは私のために働くはずです – Greg