i have clickable edittext
, when click on edittext
dialog box opens. dialog box has list populated data saved in databasehelper class.
when user selects item dialog box, dialog box should close , selected data should inserted in edittext
.
alertdialog ad; edittext selectdata; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.main_layout); final dbhelper db = new dbhelper(this); selectdata = (edittext) findviewbyid(r.id.tfselectcategory); selectdata.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub showdialog(); } }); } private void showdialog(){ dbhelper db = new dbhelper(getapplicationcontext()); final alertdialog.builder dialog = new alertdialog.builder(this); dialog.settitle("choose category"); // spinner drop down elements list<string> lables = db.sniperdata(); // creating adapter spinner arrayadapter<string> dataadapter = new arrayadapter<string>(this, android.r.layout.simple_dropdown_item_1line, lables); dialog.setadapter(dataadapter, null); alertdialog d = dialog.create(); d.show(); }
set clicklistner dialog listitem
dialog.setadapter(dataadapter,new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int item) { // write code dialog dismiss. log.e("selected item=",lables.get(item)); } });
Comments
Post a Comment