我想在appwidget上添加两个按钮,然后我想设置onclicklistener方法。
有办法吗?如何?
答案 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。