1
我用OnClickListener()時點擊startActivityForResult()時使用多個按鈕。在OnActivityResult()方法中,有不同的動作需要執行。我如何獲得正確的按鈕以獲得正確的結果?使用ActivityForResult()
@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();
}
}
}
}