在活动B 中,有imageView
用于放置selected image
。如果点击提交selected image
,listView
将返回button
A 。单击listView
A 后,它应显示相应位置的图像,并显示在活动B imageView
上。
这是listView A
点击第一个列表后,imageView
B 中显示的图片来自第二个列表,而不是第一个列表。这有什么不对?
活动B
Bitmap photo;
private static final int RESULT_LOAD_IMAGE = 1;
if(getIntent().getExtras()!=null) { //if has value pass from A
photo=getIntent().getParcelableExtra("photo");
}
private void activeGallery() {
Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RESULT_LOAD_IMAGE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case RESULT_LOAD_IMAGE:
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK & null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null,
null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
photo=decodeSampledBitmapFromUri(picturePath,200,200);
imageView.setImageBitmap(photo);
}
break;
}
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { // back to activity A
Intent returnIntent = new Intent();
returnIntent.putExtra("photo", photo);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
});
活动A
Bitmap ReceiveImage;
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { // if listView is clicked
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
mClickedPosition = position;
Intent i = new Intent(getApplication(), B.class); // pass bitmap to B
i.putExtra("photo", ReceiveImage);
startActivityForResult(i, PROJECT_REQUEST_CODE);
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { // receive from Activity B and populate ListView A
if (resultCode == RESULT_OK) {
if (requestCode == PROJECT_REQUEST_CODE) {
ReceiveImage = data.getParcelableExtra("photo");
if (mClickedPosition == -1) { // if icon clicked, add new list
if (obj != null)
obj.addNewItem(ReceiveImage);
}
else{
if (obj != null)
obj.changeItem(mClickedPosition,ReceiveImage);
}
}
}
}
答案 0 :(得分:1)
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { // if listView is clicked
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
mClickedPosition = position;
Object o = listview.getItemAtPosition(position);
Bitmap photo=image.getImage();
Intent i = new Intent(getApplication(), B.class);
i.putExtra("photo", photo);
startActivityForResult(i, PROJECT_REQUEST_CODE);
}
});
ImageAndText
是我的 ArrayList 。