当前位置:  开发笔记 > Android > 正文

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

如何解决《Remoteview中的ViewFlippershowNext()和showPrevious()无法正常工作》经验,为你挑选了0个好方法。

我正在一个项目中工作,我需要在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);

        }
    }

提前致谢

推荐阅读
手机用户2402851155
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有