0

This is my first android app and i'm new in programming, i want to show imageView inside AlertDialog, actually i searched for that but i just found that i must specify the image in the xml layout file!

like that one, i just want to get that image from the java code not from xml because that image generated by the user

That's part from my code:

                EditText et = (EditText) findViewById(R.id.editText);

                final Bitmap bm = QRCode.from(et.getText().toString()).bitmap();

                ImageView iv = (ImageView) findViewById(R.id.imagev);
                iv.setImageBitmap(bm);

                Button btn = (Button) findViewById(R.id.button);

                btn.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AlertDialog.Builder b = new AlertDialog.Builder(MainActivity.this);
                        b.setMessage("Want to save it?");
                        b.setView(iv);
                        b.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Toast.makeText(getApplicationContext(),
                                        "Tapped on YES!", Toast.LENGTH_SHORT)
                                        .show();
                            }
                        });
                        b.setNegativeButton("Delete", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Toast.makeText(getApplicationContext(),
                                        "Tapped on DELETE!", Toast.LENGTH_SHORT)
                                        .show();
                            }
                        });

                        AlertDialog ad = b.create();
                        ad.show();
                    }
                });

I want to display that "iv" in the dialog, thanks! :)

Community
  • 1
  • 1
Mohamed
  • 656
  • 9
  • 28

2 Answers2

0

If you want to create ImageView with pure java. You can use constructor to create ImageView.

    ImageView imageView = new ImageView(getApplicationContext());
    imageView.setImageResource(R.mipmap.ic_launcher);

    AlertDialog dialog = new AlertDialog.Builder(this)
            .setView(imageView)
            .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();

    dialog.show();
Leo Lin
  • 681
  • 5
  • 8
0

SOLVED

I used custom dialog...

dialog.xml

MainActivity.java

Mohamed
  • 656
  • 9
  • 28