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