0
當我的應用程序啓動時,我使用listview和第一項調用活動。我的小部件添加了新的一個項目中的onUpdate()ListView控件:在窗口小部件屏幕添加時不要調用updateAppWidget
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main_widget);
myString = context.getResources().getStringArray(R.array.quotes);
Intent active = new Intent(context, Widget.class);
active.setAction(ACTION_WIDGET_RECEIVER);
Intent archive = new Intent(context, Widget.class);
archive.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
archive.setAction(ACTION_WIDGET_ARCHIVE);
String q = myString[rgenerator.nextInt(myString.length)];
active.putExtra("msg", q);
if (getQuotes(context).size()>1)
remoteViews.setTextViewText(R.id.widget_textview, q);
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
PendingIntent archivePendingIntent = PendingIntent.getBroadcast(context, 0, archive,PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.widgetFrameLayout, archivePendingIntent);
Time now = new Time();
now.setToNow();
String mydate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
// adding new item to the listView
saveQuote(context, q, mydate);
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
}
,當用戶添加小部件到屏幕上,一個更多的項目增加了自動列出。但是我需要在android:updatePeriodMillis
期間過後再添加它。我怎樣才能實現這個?