android - ListView with Custom ArrayAdapter not updating -
i trying return custom view of textview, chrono, , checkbox. have overriden getview method not sure if did correctly. appreciate comments on arrayadapter. not update in application. thanks!
main java
public class tasktracker extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); button addbutton; addbutton=(button)findviewbyid(r.id.button1); listview mylistview= (listview)findviewbyid(r.id.listview1); final edittext myedittext= (edittext)findviewbyid(r.id.edittext1) ; //final arraylist<string> taskitems = new arraylist<string>(); final ttadapterview aa = new ttadapterview(this); // aa = new arrayadapter<string>(this, 0); mylistview.setadapter(aa); addbutton.setonclicklistener(new onclicklistener(){ public void onclick(view v){ aa.add(myedittext.gettext().tostring()); //taskitems.add(count, myedittext.gettext().tostring()); aa.notifydatasetchanged(); myedittext.settext(""); myedittext.requestfocus(); } }); } }
arrayadapter
public class ttadapterview extends arrayadapter<string> { public view v; public ttadapterview(context context){ super(context,r.layout.row); } @override public view getview(int position, view convertview, viewgroup parent){ this.v = convertview; if(v==null){ layoutinflater vi = (layoutinflater)getcontext().getsystemservice(context.layout_inflater_service); v = vi.inflate(r.layout.row, null); } return v; }
you should extend baseadapter rather arrayadapter in listview adapter class. notifydatasetchanged() little bit funky time other extend baseadapter. that's been experience @ least.
Comments
Post a Comment