public void onActivityResult(int requestCode, int resultCode, final Intent data) { if (RESULT_OK == resultCode && 1 == requestCode) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.dialog, (ViewGroup) findViewById(R.id.dialog)); Builder mydialog = new AlertDialog.Builder(ImChoose.this); mydialog.setView(layout); iv = (ImageView) layout.findViewById(R.id.iv); uri = data.getData(); ContentResolver cr = this.getContentResolver(); try { bm = BitmapFactory.decodeStream(cr.openInputStream(uri)); iv.setImageBitmap(bm); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } mydialog.setPositiveButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub // iv1.setImageURI(uri); iv1.setImageBitmap(bm); } }); // 设置重写重新选择键 mydialog.setNeutralButton("重新选择", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(intent.ACTION_GET_CONTENT); startActivityForResult(intent, 1); } }); mydialog.setNegativeButton("取消", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(ImChoose.this, "cancel", Toast.LENGTH_SHORT) .show(); } }); mydialog.create(); mydialog.show(); } super.onActivityResult(requestCode, resultCode, data); }