java - Remove data in ListView -
why when delete database , remove listview, data in arraylist not erased change null. code when added data arraylist :
list<formpermohonankredit> list = datasourcepk.getallformpk(); final listiterator<formpermohonankredit> li = list.listiterator(); final string[] listnamanasabah = new string[list.size()]; int = 0; while(li.hasnext()){ formpermohonankredit form = li.next(); string nama = form.getinfopokok() != null ? form.getinfopokok().getnama() : "null"; listnamanasabah[i] = nama; i++; } final arraylist<long> userlist = new arraylist<long>(); userlist.addall(arrays.aslist(listnamanasabah)); listadapter = new arrayadapter<string>(this, r.layout.activity_row_list, userlist); mainlistview.setadapter(listadapter);
this method delete database , remove listview :
idtable = idlist.get(position); mysqlitehelper db=new mysqlitehelper(getapplicationcontext()); db.delete("" + idtable); userlist.remove(position); listadapter.notifydatasetchanged();
i guess after changing "null" different text change, nothing has changed, it's null. arraylist after , before deleted :
- before deleted
- after deleted
i want clear arraylist selected position, not change null.
the posted code missing since not see clear relation between codes. perhaps show more code in adapter. anyway have 1 code suggestion, far can see: change from:
idlist.addall(arrays.aslist(lisnamanasabah));
to:
userlist.addall(arrays.aslist(lisnamanasabah));
notes:
- notice populating
userlist
. current code filling dataidlist
not used adapter, far can see in current posted code. explain me how results of nulls , zeros.
Comments
Post a Comment