android - Only in some phones, ListView not refresh after notifyDataSetChanged() -
it weirded because happens in phones resolution fhd.
when ui shown, seems ok. when click items , call notifydatasetchanged(), item won't refresh it's look. need click on listview anywhere again, item refresh layout correct look.
if listview changes size (ex: search function redesign whole layout), becomes ok.
here listview code:
public final class mylistview extends listview implements adapterview.onitemclicklistener { arraylist<select_item> selectlist; arraylist<id_item> idlist; showitemadapter showadapter; public mylistview(context context) { selectlist = new arraylist<select_item>(); idlist = new arraylist<id_item>(); readidlist(midlist); showadapter = new showitemadapter(context, idlist, selectlist); setadapter(showadapter); ... } @override protected void onfinishinflate() { setonitemclicklistener(this); } @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { boolean itemisselected = true; int size = selectlist.size(); // remove if click item in selectlist for(int i=0 ; i<size ; i++) { int selectid = selectlist.get(i).id; if (idlist.get(position).id == selectid) { itemisselected = false; selectlist.remove(i); showadapter.notifydatasetchanged(); break; } } if (itemisselected) { select_item item = new select_item(); item.id = idlist.get(position); selectlist.add(item); // here showadapter.notifydatasetchanged(); } ... } .... }
and here adapter code,
public final class showitemadapter extends baseadapter{ public arraylist<id_item> midlist; public arraylist<select_item> mselectlist; public showitemadapter(context context, arraylist<id_item> idlist, arraylist<select_item> selectlist) { midlist = idlist; mselectlist = selectlist; } @override public int getcount() { int ret = midlist.size(); return ret; } @override public object getitem(int position) { return position; } @override public long getitemid(int position) { return position; } @override public view getview(int position, view convertview, viewgroup parent) { ... for(int i=0 ; i<size ; i++) { // selected if (midlist.get(position).id == selectlist.get(i).id) { misselected = true; break; } } if (misselected) { textview.setbackgroundcolor(color.red); } else { textview.setbackgroundcolor(color.white); } } }
anybody give me hand?
i found phones work correctly cause same issue when debugging pause @ getview(). think .. "views has been updated won't refresh views." views update during debugging make ui not refresh actually, works in wrong way.
i guess refreshing views.
i see possible code conflict , timing issue between getview() of adapter , onitemclick().
allow me explain. in getview(), there code
if (midlist.get(position).id == selectlist.get(i).id)
note: checks value of selectlist
, not declared in adapter class. assume meant mselectlist
. let's move on...
in onitemclick(), there code
if (idlist.get(position).id == selectid) { ... selectlist.remove(i); ...
note: code removes item selectlist
, while in getview
(), checking same object. cannot know code run first. have idea... getview
() virtual callback method baseadapter may trigger method when requires row or item display. when remove item listview, adapter may not request refresh, no matter in code. , adapter showitemadapter
responsible row/views refresh.
suggestion: place same code (for remove/add item) in getview
() avoid these kind of code conflicts.
let know , luck odd anomaly.
tommy kwee
Comments
Post a Comment