dialog - Adding a custom image to AlertDialog [ANDROID] -
i'm trouble trying add image alertdialog. image not same, it's different everytime.
what i'm trying do, adding image alertdialog (if it's possible imageview, , not icon of dialog) knowing name. trouble have thousand images.
1) so, when calling builder.seticon(int iconid) dunno how pass iconid instead of name of picture. considering i'm using different image every time.
2) advice on how put image imageview (considering there's layout associated dialog)?
update have string s = scanqr.substring(start, 21);
result of scan qr-code reader.
this string contain name of image want put in alertdialog. now, here code dialog:
@override public dialog oncreatedialog(bundle savedinstancestate) { alertdialog.builder builder = new alertdialog.builder(getactivity()); layoutinflater inflater = getactivity().getlayoutinflater(); builder.setview(inflater.inflate(r.layout.dialog_single_work, null)) //here icon (better imageview, dunno how it) .seticon() .setpositivebutton("pos", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { } }) .setnegativebutton("neg", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { } }); return builder.create(); } }
the method .seticon requires or int (iconid) or drawable object. have name (string s) of image. how can solve it?
builder.seticon();
setting icon alertdialog
placed left of dialog's title. understand want add image dialog, not icon. achieve should add custom view dialog :
view mview = view.inflate(this, r.layout. dialog_single_work, null); imageview mimage = (imageview) mview.findviewbyid(r.id.image); // use imageview set image builder.setview(mview);
and add imageview
in it's layout can set image. thing trying achieve?
edit: :
public void showdialog(int result){ switch(result){ case 0: mimageview.setimageresource(r.drawable.my_icon); break; case 1: mimageview.setimageresource(r.drawable.my_second_icon); break; // , on... or string or whatever response. } }
edit2: can image resources using string this:
string mdrawablename = "myappicon"; int resid = getresources().getidentifier(mdrawablename , "drawable", getpackagename());
Comments
Post a Comment