2
看看下面的代碼我需要每秒更新一次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);
}
}
應用程序小部件的設計不是每秒更新一次。 – CommonsWare 2012-02-10 13:29:12
但這不是我的問題的答案。 – Adam 2012-02-11 09:12:53
你會注意到我沒有提供它作爲答案,而是作爲評論。 – CommonsWare 2012-02-11 11:59:35