【问题标题】:ViewFlipper inside Remoteview showNext() and showPrevious() not workingRemoteview showNext() 和 showPrevious() 中的 ViewFlipper 不起作用
【发布时间】:2016-04-16 07:01:15
【问题描述】:

我正在一个项目中工作,我需要在通知栏中的 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;
    }

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

        }
    }

提前致谢

【问题讨论】:

  • 您找到解决方案了吗? ,我被困在同一点上。

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


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多