0

What I was trying to do is an app that read QR-CODES (referred to images) and just after the reading, showing a Dialog with the image related to the QR-CODE and the description taken by a database.

Any advice on how to do that?

What I could find on the Internet was just how to create Dialog with custom layout. Nothing more.

Renjith
  • 5,783
  • 9
  • 31
  • 42
Stefano Munarini
  • 2,711
  • 2
  • 22
  • 26

3 Answers3

2

I assume you need t o display a Image in a custom dialog

Define 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>

In your activity on button click display a dialog

 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

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
0

you can use setContentView() n just pass ImageView as parameter to it.

d3m0li5h3r
  • 1,957
  • 17
  • 33
0

For custom Dialog you have to just create one layout and set that layout in dialog.

e.g

dialog.setContentView(R.layout.customdialog);

See this example,Click Here.

Dhruv
  • 1,862
  • 3
  • 20
  • 38