android - Remoteview showNext() 和 showPrevious() 中的 ViewFlipper 不工作

标签 android notifications android-appwidget viewflipper android-remoteview

我在一个项目中工作,我需要在通知栏的 Remoteview 中使用 ViewFlipper View 。目前正面临 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;
    }

因此,当触发点击事件时,我必须更改 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);

        }
    }

提前致谢

最佳答案

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

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

这里 0 将是您需要更新的通知的唯一 ID

关于android - Remoteview showNext() 和 showPrevious() 中的 ViewFlipper 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34730523/

相关文章:

javascript - phonegap geocoder.geocode 从结果中获取门牌号

jenkins - 更新 Jenkins 插件的问题

android - 未播放通知声音。权限拒绝

android - 应用小部件中的 AdapterViewFlipper : setPendingIntentTemplate() and setOnClickFillInIntent() not working

android - 从程序内更新 AppWidget?

android - 阻止 Android 重新创建已经存在的 Activity

java - 如何获取四方 field 列表 - Android

java - 警报管理器不工作

c++ - 如何覆盖嵌套的 C++ 对象方法?

android - 在主屏幕上获取应用程序/小部件?