android - how to get the edit text value out of an editable listview -
i created editable custom listview button outside listview. want save edittext value entered user on button click. edit text in base adapter class , list , button in activity class, i'm having problem accessing edit text list , code crashes because of null pointer exception
public class productslist extends activity{ productlistadapter dataadapter; progressdialog progressdialog=null; listview listview; usersqlitedb usersqlite_obj; arraylist<products> prodlist; edittext edchemistname, edchemistaddr; button btnsave; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.productlist); edchemistname = (edittext) findviewbyid(r.id.edittext1); edchemistaddr = (edittext) findviewbyid(r.id.edittext2); btnsave =(button)findviewbyid(r.id.button1); listview = (listview)findviewbyid(r.id.listview1); usersqlite_obj = new usersqlitedb(this); progressdialog = progressdialog.show(this, "saved","please wait...", true); // new thread() { runonuithread(new runnable() { public void run() { try{ usersqlite_obj.open(); prodlist = new arraylist<products>(); prodlist = usersqlite_obj.getproductslist(); log.e("prodlist", "1"); dataadapter = new productlistadapter(productslist.this,prodlist); listview.setadapter(dataadapter); usersqlite_obj.close(); } catch (exception e) { log.d("error",e.getmessage()); } dismissloadingdialog(); } }); } public void buttonclick(view v) { for(int i=0;i<listview.getcount();i++){ view row = listview.getchildat(i); log.e("edittext clicked", "yes"); edittext edittext= (edittext) row.findviewbyid(r.id.ed); if (edittext.length()>0){ string text = edittext.gettext().tostring(); log.e("extracted text", "text"); } }
if u want use edittext data of listview in ur adapter class u should pass liatview in adapter class or can set adapter in activty file.
Comments
Post a Comment