android - How to force ListView to Invalidate -
i'm new android development, i've studied posts of site , have tried many different suggestions still can't solve problem.
i refer here implement drop-&-drop list view (i.e. user can long-press , drag list item reorder position. created custom listview, adapter , listactivity. here part of code of listactivity:
public class dragndroplistactivity extends listactivity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.dragndroplistview); arraylist<string> content = new arraylist<string>(mlistcontent.length); (int i=0; < mlistcontent.length; i++) { content.add(mlistcontent[i]); } setlistadapter(new dragndropadapter(this, new int[]{r.layout.dragitem}, new int[]{r.id.textview01}, content));//new dragndropadapter(this,content) listview listview = getlistview(); if (listview instanceof dragndroplistview) { ((dragndroplistview) listview).setdroplistener(mdroplistener); ((dragndroplistview) listview).setremovelistener(mremovelistener); ((dragndroplistview) listview).setdraglistener(mdraglistener); } listview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view view, int position, long id) { log.i("", "onitemclick"); } }); } private droplistener mdroplistener = new droplistener() { public void ondrop(int from, int to) { listadapter adapter = getlistadapter(); if (adapter instanceof dragndropadapter) { ((dragndropadapter)adapter).ondrop(from, to); getlistview().invalidateviews(); } } };
my problem is: when dragged & dropped item new position, replaced properly. after that, when tried drag item again, previous item in position shown. problem recovered if put app background , put again.
inside "ondrop", list view invalidated. i've learned site invalidateviews() not run immediately, seems invalidateviews() never run until put app background ?! how can force list view redraw ?
more information: app ran in emulator problem happened in galaxy phone (4.1.2).
hope help, many !
check if works :
private droplistener mdroplistener = new droplistener() { public void ondrop(int from, int to) { listadapter adapter = getlistadapter(); if (adapter instanceof dragndropadapter) { ((dragndropadapter)adapter).notifydatasetchanged(); ((dragndropadapter)adapter).ondrop(from, to); getlistview().invalidate(); } }
};
Comments
Post a Comment