好的,所以我已经尝试了几乎所有我想到的东西但是我的小部件上的这个按钮在触摸时根本没有响应。我想在单击按钮时打开另一个类和关联的xml,但事件没有响应.. 以下是我的onUpdate()代码
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, Launch.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget1);
views.setOnClickPendingIntent(R.id.button, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
<receiver
android:name="com.example.widgetexample.ExampleAppWidgetProvider"
android:label="8-bit cloud widget 1" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget1_inf" />
</receiver>
应用程序运行成功后,它意外停止的错误..widget添加到屏幕但按钮不起作用..p.s我是新的android.Thanks提前