I don't know how to put an image into an AlertDialog.
I have this code, but i think this is not possible.
AlertDialog.Builder alert = new AlertDialog.Builder(MessageDemo.this);
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
imageView.setImageResource(R.drawable.cw);
alert.setView(imageView);
alert.setNeutralButton("Here!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
}
});
alert.show();
Create one
sample.xml
and addImageView
in that XML.sample.xml
Java Code :
For images I just do this:
In addition to the other answers, i want to add the point that you should not be obliged to use AlertDialog. For example, in my case i want to show only imageView in a dialog and AlertDialog didn't worked for this case. The below solution worked for me :
myphoto_layout.xml :
If you want to add image to your layout dynamically, you can use the below code :
You could do it in the following way. This will show an alertDialog with a message (if you don't need the message, just remove that line) and the image (and an OK button):
there is an another option you can put an image in alert dialog without creating an xml file.