以下のコードを見てください。このonUpdateメソッドを毎秒更新する必要があります。誰か良い例を教えてください。主にコードをからに更新する必要がありCurFreq(context);
ますviews.setTextViewText(R.id.text_widget_batt, prefNameBattery+"%");
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, MyActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setOnClickPendingIntent(R.id.layout_widget, pendingIntent);
CurFreq(context);
Temp(context);
Battery(context);
SharedPreferences myPrefsInfo = context.getSharedPreferences("myPrefsInfo", Context.MODE_PRIVATE);
String prefNameCurFreq = myPrefsInfo.getString(WidgetCurFreq, "");
String prefNameTemp = myPrefsInfo.getString(WidgetTemp, "");
String prefNameBattery = myPrefsInfo.getString(WidgetBattery, "");
views.setTextViewText(R.id.text_widget_freq, prefNameCurFreq);
views.setTextViewText(R.id.text_widget_temp, prefNameTemp+",0°C");
views.setTextViewText(R.id.text_widget_batt, prefNameBattery+"%");
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}