2013-05-09 67 views
0

我試圖做的是一個讀取QR-CODES(參考圖像)的應用程序,剛讀完之後,顯示一個對話框,其中包含與QR-CODE相關的圖像以及由一個數據庫。將自定義圖像添加到對話框

有關如何做到這一點的任何建議?

我能在互聯網上找到的只是如何使用自定義佈局創建對話框。而已。

+0

你要買什麼,如何讓自定義對話框..是你的問題 – CRUSADER 2013-05-09 11:29:23

+0

你需要顯示在定製對話框的自定義圖像? – Raghunandan 2013-05-09 11:30:26

+1

@Raghunandan是的,就是這樣。你知道該怎麼做? – 2013-05-09 11:35:03

回答

2

我假設你需要在自定義對話框中顯示的圖像

定義dialog.xml

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

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 

在你點擊按鈕上的活動顯示對話框

Button b= (Button) findViewById(R.id.button1); 
    b.setOnClickListener(new OnClickListener() 
    { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      showpopup();   
     } 

    }); 

    public void showpopup() 
    { 
    Dialog d = new Dialog(MainActivity.this); 
    d.setContentView(R.layout.dialog); 
    d.setTitle("my title"); 
    ImageView iv = (ImageView) d.findViewById(R.id.imageView1); 
    iv.setImageResource(R.drawable.afor); 
    // set your image here. I have used a resource from the drawable folder 
    d.show(); 
    } 

enter image description here

+0

非常感謝你@Raghunandan。你在一秒鐘內就得到了我的問題,現在我可以做我想做的事!現在我試圖從數據庫中獲得描述 – 2013-05-09 12:00:01

+0

@StefanoMunarini很高興幫助 – Raghunandan 2013-05-09 12:00:52

+0

對不起,這是一個missclick。你說對了!非常感謝 – 2013-05-09 12:01:57

0

您可以使用setContentView() n只是將ImageView作爲參數傳遞給它。

+0

我想添加一個自定義圖像。 – 2013-05-09 12:00:39

0

對於自定義對話框,您必須創建一個佈局並在對話框中設置該佈局。

dialog.setContentView(R.layout.customdialog); 

看到這個例子,Click Here.