fr4n fr4n - 5 months ago 25
Android Question

How to put an image in an AlertDialog?? Android

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();

Answer

first create one sample.xml and add imageview in that xml..

AlertDialog.Builder alertadd = new AlertDialog.Builder(
                MessageDemo.this);
LayoutInflater factory = LayoutInflater.from(MessageDemo.this);
final View view = factory.inflate(R.layout.sample, null);
alertadd.setView(view);
alertadd.setNeutralButton("Here!", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dlg, int sumthin) {

                }
            });

alertadd.show();
Comments