我有一个活动,要求用户构建一顿饭。在这里,他们有12个食物选项可供选择(以图像按钮表示)。我希望用户能够单击这些图像按钮中的四个,并继续下一个活动。但是,我不知道如何在下一个活动中显示4个用户选择的图像按钮。我尝试过使用putExtra()和getExtra()命令,但似乎无法理解。
发布于 2017-04-05 06:10:14
//The Images you want, save as bitmap
imageView.buildDrawingCache();
Bitmap image= imageView.getDrawingCache();
//Create a extras bundle and put bitmap in with key
Bundle extras = new Bundle();
extras.putParcelable("imagebitmap", image);
//Create a new intent and pass in the bundle
Intent intent = new Intent(CurrentActivity.this, NextActivity.class);
intent.putExtras(extras);
startActivity(intent);
//In next activity, grab the extras
Bundle extras = getIntent().getExtras();
//Get the saved bitmap with the key value into a bitmap object
Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
//Set it
image.setImageBitmap(bmp );至于这背后的逻辑,我真的帮不上忙,因为我看不到你的代码。但我会在所有的图像视图上建立onClickListeners,并跟踪正在点击的内容
imgView.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
if (count < 4) {
imgView.buildDrawingCache();
Bitmap image= imageView.getDrawingCache();
extras.putParcelable("imagebitmap" + count, image);
} else {
//Tell them to deselect, or add an operation to deselect, and decrement counter
}
}
});https://stackoverflow.com/questions/43218433
复制相似问题