[問題] 客製化optionDialog
請問各位神手們
我想在按下ImageButton會有對話框出現
對話框有三個選項分別是"從本機擷取""照張相片""取消"
現在就卡在"從本機擷取"
可以從本機擷取
但是擷取後卻無法將預設圖片換成自己選取的圖片
依舊是預設圖片
以下是程式碼
請各位看看哪裡有錯 謝謝
private OnClickListener sel=new OnClickListener(){
public void onClick(View v){
openOptionDialog();
}
};
private void openOptionDialog(){
new AlertDialog.Builder(Select.this)
.setTitle(R.string.select_title)
.setMessage(R.string.select_msg)
.setPositiveButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int i) {
}
})//end setPositiveButton
.setNegativeButton("從本地擷取", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int c) {
Intent intent =new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent,1); }
================以下開始有錯誤=================================
@Override
protected void onActivityResult(int requestCode,int resultCode, Intent data)
{
if (resultCode==RESULT_OK)
{
Uri uri=data.getData();
ContentResolver cr=this.getContentResolver();
try{
Bitmap bitmap=BitmapFactory.decodeStream(cr.openInputStream(uri));
btn_01.setImageBitmap(bitmap); }
catch(FileNotFoundException e){
e.printStackTrace(); }
}//end if
super.onActivityResult(requestCode, resultCode, data);
}//end onActivityResult
}//end OnClickListener
)//end setNegativeButton
.show();
}//end openOptionDialog
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.173.77.221
※ 編輯: d831007 來自: 218.173.77.221 (06/09 21:46)
→
06/09 21:50, , 1F
06/09 21:50, 1F
※ 編輯: d831007 來自: 218.173.77.221 (06/09 21:52)
→
06/09 21:54, , 2F
06/09 21:54, 2F
→
06/09 21:55, , 3F
06/09 21:55, 3F
→
06/09 21:56, , 4F
06/09 21:56, 4F
→
06/09 21:58, , 5F
06/09 21:58, 5F
→
06/09 21:58, , 6F
06/09 21:58, 6F
推
06/16 01:36, , 7F
06/16 01:36, 7F