Remoteview中的ViewFlipper showNext()和showPrevious()无法正常工作

时间:2016-01-11 20:31:16

标签: android notifications android-appwidget viewflipper android-remoteview

我正在一个项目中工作,我需要在Notification栏的Remoteview中使用ViewFlipper视图。目前我正面临着showNext()和showPreview()的问题。但不幸的是,当我调用按钮时,不会调用showNext()和showPreview()。我也发布了我的代码供您参考。如果我的问题不明确,请帮助我在哪里犯错误并纠正我。

 private Notification setCustomViewNotification() {

        // Creates an explicit intent for an ResultActivity to receive.
        Intent resultIntent = new Intent(this, ResultActivity.class);

        // This ensures that the back button follows the recommended convention for the back key.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(ResultActivity.class);

        // Adds the Intent that starts the Activity to the top of the stack.
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        // Create remote view and set bigContentView.
         expandedView = new RemoteViews(this.getPackageName(), R.layout.notification_viewflipper);
//        expandedView.set(R.id.text_view, "Neat logo!");

        expandedView.setOnClickPendingIntent(R.id.img_left,getPendingSelfIntent(MainActivity.this, IMAGE_LEFT));
        expandedView.setOnClickPendingIntent(R.id.img_right,getPendingSelfIntent(MainActivity.this, IMAGE_RIGHT));


        Notification notification = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setAutoCancel(true)
                .setContentIntent(resultPendingIntent)
                .setContentTitle("Custom View").build();

        notification.bigContentView = expandedView;

        return notification;
    }

因此,当触发click事件时,我必须更改ViewFlipper项。以下是我完全坚持的代码。

public void onEvent(ViewFlipperClickEvent event){
        if(event.getTag().equals(MainActivity.IMAGE_LEFT)){


            expandedView.showPrevious(R.id.ViewFlipper01);

        }else if(event.getTag().equals(MainActivity.IMAGE_RIGHT)){
            expandedView.showNext(R.id.ViewFlipper01);

        }
    }

提前致谢

1 个答案:

答案 0 :(得分:0)

您需要通知推送通知的更改 尝试类似的东西-

notificationBig.showNext(R.id.vf_carousel)
notificationManager.notify(0, customNotif.build())

此处0是您需要更新的通知的唯一ID