6

通知バーの 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);

        }
    }

前もって感謝します

4

1 に答える 1