如何添加视图到远程视图android通知

时间:2012-03-02 07:38:27

标签: android

我想在单个通知中创建自定义通知列表。 为此,我使用远程视图和循环我添加了其他视图。 但我看不到我的嵌套视图。 我的代码是,

public static void ShowNotification(ArrayList<ReminderNotification> arr) {
        // TODO Auto-generated method stub
        Logger.debug("size:" + arr.size());

        Notification notification = new Notification(R.drawable.icon, mContext
                .getString(R.string.app_name), System.currentTimeMillis());
        notification.sound = Uri.parse("android.resource://"
                + mContext.getPackageName() + "/" + R.raw.pluck_b);
        RemoteViews contentView = new RemoteViews(mContext.getPackageName(),
                R.layout.notification);
        for (ReminderNotification obj : arr) {
            RemoteViews nested = new RemoteViews(mContext.getPackageName(),
                    R.layout.notification);
            Intent notificationIntent = new Intent(mContext,
                    ToothBrushTimer.class);
            PendingIntent contentIntent = PendingIntent.getActivity(mContext,
                    0, notificationIntent, 0);
            nested.setOnClickPendingIntent(obj.getId(), contentIntent);
            nested.setImageViewResource(R.id.image, R.drawable.icon);
            nested.setTextViewText(R.id.title, mContext
                    .getString(R.string.app_name));
            nested.setTextViewText(R.id.text, obj.getName());
            contentView.addView(R.id.layout, nested);
        }
        notification.contentView = contentView;
        Intent notificationIntent = new Intent(mContext, ToothBrushTimer.class);
        PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0,
                notificationIntent, 0);
        notification.contentIntent = contentIntent;

        NotificationManager nm = (NotificationManager) mContext
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        nm.notify(0, notification);
    }

请帮我出来

0 个答案:

没有答案