2012-05-29 85 views
-1

我有一個圖像,我目前正在將它設置在imageview上。在對話框中顯示圖像

我希望當點擊Imageview時,會彈出一個對話框,顯示圖像..任何方法我怎麼能實現這一點。

   Context mContext = getApplicationContext(); 
       Dialog dialog = new Dialog(mContext); 

       dialog.setContentView(R.layout.customdialog); 
       dialog.setTitle("wateva"); 

       ImageView ivDialog = (ImageView) dialog.findViewById(R.id.ivDialog); 
       String filepath = Environment.getExternalStorageDirectory().getPath(); 
       folder = new File(filepath,"checking"); 

       File fa = new File(folder,"bmp1.png"); 
       Bitmap bmpa = BitmapFactory.decodeFile(fa.getAbsolutePath()); 
       Log.d("error " , "here"); 
       ivDialog.setImageBitmap(bmpa); 
       dialog.show(); 
+0

做ü谷歌搜索:http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog –

回答

2

使用CustomDialog爲.Create佈局具有ImageView的行吟詩人和組件並將其設置爲對話框。

Dialog dialog = new Dialog(this); 
dialog.setContentView(R.layout.dialoglayout); 
ImageView imgView=(ImageView)dialog.findViewById(R.id.imagview); 
//set image to imgView 
dialog.show(); 
+0

感謝我西港島線看這個:-) – Kumar

+0

'ImageView的ivDialog =(ImageView的) dialog.findViewById(R.id.ivDialog);'............看到我的代碼 –

+0

現在我即將得到這個錯誤android.view.WindowManager $ BadTokenException:無法添加窗口 - 標記空是不適用於應用程序 – Kumar