Android appwidget,我可以把按钮放在上面吗?

时间:2010-12-01 18:26:05

标签: android android-appwidget

我想在appwidget上添加两个按钮,然后我想设置onclicklistener方法。

有办法吗?如何?

1 个答案:

答案 0 :(得分:3)

RemoteViews views = new RemoteViews(context.getApplicationContext(), R.layout.main_view);

Intent intent = new Intent(context, InputBroadcastReceiver.class); // receiver class
intent.putExtra(EXTRA_ID, id); // some extras

PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);             views.setOnClickPendingIntent(R.id.my_button, pendingIntent);

然后覆盖InputBroadcastReceiver中的onReceive方法并享受您的输入;)

BroadcastReceivers正在解释here