1
爲什麼不接受調用當我點擊Button wid?Android小工具:OnClickPendingIntent不會工作
代碼:
public class Widget extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int i = 0; i < appWidgetIds.length; i++) {
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, Widget.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setOnClickPendingIntent(R.id.wid, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
Log.d("ARH","CLICKK");
}
監守我需要一個按鈕來手動刷新小部件,但似乎只有Log.d("ARH","CLICKK");
被調用時,我加入了Widget。
謝謝!
好聽的有趣!你知道我如何從一個小部件獲得OnClick並更新文本? – 2012-03-24 16:54:16
您可以讓小部件發送您自己的操作(不是更新操作),然後在onReceive函數中捕獲它。 – Ran 2012-03-26 08:05:33
已經完成,但不錯! – 2012-03-26 12:44:59