i want know how text edittext, using button, , place in listview. have tried code:
public class mainactivity extends activity { button send; edittext textbox; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); send = (button) findviewbyid(r.id.sendbtn); textbox = (edittext) findviewbyid(r.id.textbox); edittext text = (edittext) findviewbyid(r.id.textbox); string textbox = text.gettext().tostring(); string arr[] = {}; lv = (listview) findviewbyid(r.id.list); arrayadapter<string> adapter = new arrayadapter<string>(getapplicationcontext(), r.layout.activity_main, arr); lv.setadapter(adapter); textbox.setonclicklistener(new onclicklistener() { public void onclick(view arg0) {} }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
first, set onclicklistener button. in listener, grab text edittext via textbox.gettext().tostring(). next want update the listview's list adapter newly selected text. there number of ways this
- update adapter , notify
listviewof change - rebuilt array of
strings, set adapterlistviewagain
Comments
Post a Comment