2

我裝箱的一個AlertDialog這是二選一個開放的攝像頭和另一種是畫廊如何將圖像添加到Android中的AlertDialog?

的圖像,如圖
enter image description here

,但我需要相機和畫廊圖像添加到像這樣

enter image description here

如何添加圖像是這樣的代碼

final String [] items = new String [] {"Take from camera", "Select from gallery"};  
     ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.select_dialog_item,items); 
     AlertDialog.Builder builder = new AlertDialog.Builder(this); 

     builder.setTitle("Select Image"); 
     builder.setAdapter(adapter, new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int item) { //pick from camera 
     if (item == 0) { 
     Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

     mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), 
     "tmp_avatar_" + String.valueOf(System.currentTimeMillis()) + ".jpg")); 

     intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri); 

     try { 
     intent.putExtra("return-data", true); 

     startActivityForResult(intent, PICK_FROM_CAMERA); 
     } catch (ActivityNotFoundException e) { 
     e.printStackTrace(); 
     } 
     } else { //pick from file 
     Intent intent = new Intent(); 

     intent.setType("image/*"); 
     intent.setAction(Intent.ACTION_GET_CONTENT); 

     startActivityForResult(Intent.createChooser(intent, "Complete    action    using"), PICK_FROM_FILE); 
     } 
     } 
     }); 

     final AlertDialog dialog = builder.create(); 



     dialog.show(); 

} 
+0

U可以dialog.http使用定製:// www.mkyong.com/android/android-custom-dialog-example/ –

回答

5

創建佈局像你想然後在您的對話添加布局

佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="5dp" /> 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textColor="#FFF" 
     android:layout_toRightOf="@+id/image" /> 

    <Button 
     android:id="@+id/dialogButtonOK" 
     android:layout_width="100px" 
     android:layout_height="wrap_content" 
     android:text=" Ok " 
     android:layout_marginTop="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_below="@+id/image" /> 

</RelativeLayout> 

然後在活動

​​
+0

如何爲一個列表? – khunshan

相關問題