提前感谢,我正在尝试将值从一个活动传递到另一个活动。
但是,当用户单击列表视图图像时,我的大部分代码都可以在另一个活动中显示该图像。
活动 A 在这里我正在尝试传递当前单击的图像
mSelfieAdapter = new SelfieImageAdapter(this,
R.layout.selfie_list,
imageArry);
ListView dataList = (ListView) findViewById(R.id.list);
dataList.setAdapter(mSelfieAdapter);
// up to here the listview is displayed for the user.
dataList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
List<SelfieImage> selfs = db.getAllSelfies();
Intent i = new Intent(DailySelfieActivity.this, Camera.class);
// Pass all data flag
i.putExtra("image",imageInByte );
System.out.println(imageInByte);
// Pass a single position
i.putExtra("position", position);
// Open SingleItemView.java Activity
startActivity(i);
}
});
活动 B 在这里,我正在尝试以全尺寸显示图像。
public class Camera extends Activity {
byte imageInByte[];
ImageView imgflag;
int position;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.singleitemview);
Intent i = getIntent();
position = i.getExtras().getInt("position");
imageInByte = i.getByteArrayExtra("image");
System.out.println(imageInByte);
imgflag = (ImageView) findViewById(R.id.flag);
imgflag.setImageResource(imageInByte[position]);
}
}
**我已经通过将上面的代码更改为:**解决了上述问题
Intent i = getIntent();
imageInByte = i.getByteArrayExtra("image");
imgflag = (ImageView) findViewById(R.id.flag);
Bitmap bm = BitmapFactory.decodeByteArray(imageInByte, 0, imageInByte.length);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
imgflag.setImageBitmap(bm);
imgflag.setScaleType(ImageView.ScaleType.FIT_XY);