java - Android AlertDialog SetText -


hi have alertdialog create when click on item in listview, im trying name of file,description, author etc.. activity , display in alertdialog .settext not work, can please help. thank you, here code: http://pastebin.com/fzwspp5e

this not @ how use dialogs in android. need define dialogs in override of oncreatedialog, described in documentation:

http://developer.android.com/guide/topics/ui/dialogs.html 

following guide, should able fix problem. here's example copied , pasted random app:

@override protected dialog oncreatedialog(int id, bundle b) {     layoutinflater inflater = (layoutinflater) this.getsystemservice(this.layout_inflater_service);     alertdialog.builder builder = null;     switch(id) {         case dialog_block_size:         {             dialog dialog = new dialog(this);             final view dialoglayout = inflater.inflate(r.layout.dialog_block_size, null);             builder = new alertdialog.builder(this);             builder.setview(dialoglayout);             builder.settitle("set block size");              final edittext blockin = (edittext)dialoglayout.findviewbyid(r.id.block_size_in);             blockin.settext(new integer(pref.getint("block_size", 6)).tostring());              builder.setpositivebutton("ok", new dialoginterface.onclicklistener() {                     public void onclick(dialoginterface dialog, int id) {                         sharedpreferences.editor editor = pref.edit();                         editor.putint("block_size", new integer(blockin.gettext().tostring()));                         editor.commit();                         ////////todo///////////                         //notify minutemaidservice have changed block_size                         dialog.dismiss();                     }                 });             builder.setnegativebutton("cancel", new dialoginterface.onclicklistener() {                     public void onclick(dialoginterface dialog, int id) {                         dialog.cancel();                     }                 });             dialog = builder.create();             return dialog;         }         default:         {             return null;         }     }     return dialog; } 

with above code, can call showdialog(dialog_block_size) show dialog. note dialogs created once , shown on , on again. force rebuilding dialog, call removedialog(int) before calling showdialog(int). overriding onpreparedialog() best method, using removedialog works , it's easier.


Comments