【发布时间】:2018-05-30 17:32:33
【问题描述】:
这是我的 res/xml/widget.xml
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="5" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
这是我的 AppWidgetProvider 文件:
@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) {
Intent intent = new Intent(context,MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context,0,intent,0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget);
views.setOnClickPendingIntent(R.id.button,pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId,views);
// views.setTextViewText(R.id.textView,"2");
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}
然后按下按钮(+),textview 添加一个\textview=6。然后按下按钮(-),textview = 4 请帮助我,我需要任何解决方案。
【问题讨论】:
-
我不明白如何在更改文本视图中使用挂起的意图?请帮帮我
标签: android widget android-pendingintent