当单击 startActivityForResult() 时,我正在使用带有 OnClickListener() 的多个按钮。在 OnActivityResult() 方法中,需要执行不同的操作。我如何获得正确的按钮来获得正确的结果?
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.camImgButton:
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, picture);
break;
case R.id.galImgButton:
i = new Intent();
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(i, REQUEST_CODE);
break;
case R.id.txtButton:
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
switch ( ) {
case :
if (resultCode == RESULT_OK) {
// We need to recyle unused bitmaps
if (bmp != null) {
bmp.recycle();
}
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
display.setImageBitmap(bmp);
break;
case :
InputStream stream = null;
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK)
try {
// We need to recyle unused bitmaps
if (bmp != null) {
bmp.recycle();
}
stream = getContentResolver().openInputStream(data.getData());
bmp = BitmapFactory.decodeStream(stream);
display.setImageBitmap(bmp);
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (stream != null)
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}