2016-05-30 3 views
1

[これは空白を表示するダイアログボックスですImageViewギャラリーから選択した画像をカスタムダイアログのImageViewに表示しようとしていますが、ImageViewが表示されますブランク。しかし、それはnullではありません。以下に添付するコードスニペットを示します。Galleryから画像を選択して表示した後、空白になります

public void loadImagefromGallery(View view) { 
     Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); 
     photoPickerIntent.setType("image/*"); 
     startActivityForResult(photoPickerIntent, SELECT_PHOTO); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     try { 
      if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK && null != data) { 
       Uri selectedImage = data.getData(); 
       String[] filePathColumn = { MediaStore.Images.Media.DATA }; 

       Cursor cursor = getContentResolver().query(selectedImage, 
         filePathColumn, null, null, null); 
       cursor.moveToFirst(); 

       int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
       String picturePath = cursor.getString(columnIndex); 
       cursor.close(); 


       final Dialog dialog = new Dialog(SelectImagesActivity.this); 
       dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
       dialog.setContentView(R.layout.upload_image); 
       ImageView imageView = (ImageView) dialog.findViewById(R.id.imageView1); 
       imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 
       EditText editText = (EditText)dialog.findViewById(R.id.keyWords); 
       Button button = (Button)dialog.findViewById(R.id.done); 
       dialog.setCancelable(false); 
       dialog.getWindow().setLayout(550, 900); 
       dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
       dialog.show(); 
       imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 

      } else { 
      Toast.makeText(this, "You haven't picked Image", 
        Toast.LENGTH_LONG).show(); 
     } 
    } catch (Exception e) { 
     Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG) 
       .show(); 
    } 

} 

助けてください。ありがとう。

+0

にスクリーンショットを共有しています。 –

+0

'String picturePath = cursor.getString(columnIndex);'は画像の適切な絶対パスを返します。 –

答えて

0

変更

dialog.show(); 
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 

imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 
dialog.show(); 
+0

nope.まだ仕事していない! – Neer

関連する問題