1
我有顯示簡單的文本和3個按鈕的窗口小部件:處理多個按鈕的小窗口內 - 的Android
- 刷新(精選另一個隨機字符串並把它顯示)
- 複製(複製的內容的TextView到剪貼板)
- 分享(分享的TextView到
我已經得到了刷新按鈕的設置和工作得很好的社交媒體和等)的內容,但我似乎無法想出一個辦法處理另兩個按鈕
PS。我不需要實際的代碼我已經知道該怎麼做複製和分享我只需要知道
這裏點擊如何處理事件,是迄今爲止我的代碼:
Button copy_content;
Button share_content;
void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
/** Code below will be executed once the timer is over*/
String widgetText = RandQuotes[rand.nextInt(RandQuotes.length)];
// Construct the RemoteViews object
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.quotes_widget);
views.setTextViewText(R.id.sayings, widgetText);
// Instruct the widget manager to update the widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
final int count = appWidgetIds.length;
for (int i = 0; i < count; i++) {
int widgetId = appWidgetIds[i];
String on_sayings = RandQuotes[rand.nextInt(RandQuotes.length)];
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.quotes_widget);
remoteViews.setTextViewText(R.id.sayings, on_sayings);
Intent intent = new Intent(context, HavamalWidget.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.switch_trigger, pendingIntent);
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
}
而下面我迷路了你的指示,你可以發佈完整的答案嗎? –
只是再次檢查答案 –
我遇到了一些'CommonRemoteViewBuilder'的麻煩,並且操作按鈕'ACTION_BUTTON_COPY'和'ACTION_BUTTON_REFRESH'被稱爲「無法解析符號」 –