自定义扩展视图的事件已添加到状态栏通知?

时间:2011-02-27 14:48:43

标签: android

从此链接我可以将状态栏添加到状态栏。 http://developer.android.com/guide/topics/ui/notifiers/notifications.html。 但是如何为它定义事件。 假设我是addind两个按钮,而不是如何为按钮设置onclick事件。

这是我的远程视图代码。

RemoteViews contentView=new RemoteViews(getPackageName(),R.layout.demo);
        notification.contentView = contentView;

        notification.flags |= Notification.FLAG_NO_CLEAR;
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        Intent intent = new Intent(getApplicationContext(), Main.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                intent, Intent.FLAG_ACTIVITY_NEW_TASK);

        notification.contentIntent=contentIntent;
        nm.notify(NOTIFY_ID, notification);

这里是R.layout.demo按钮,我可以定义事件,可以详细说明。 thankx

1 个答案:

答案 0 :(得分:1)

RemoteViews上,拨打setOnClickPendingIntent(),提供PendingIntent,点击该按钮时会调用该{{1}}。