android - ArrayAdapter with Filter crashes -
i have own arrayadapter
, inside of adapter class have filter
. in filter overriding publishresults(charsequence constraint, filterresults result)
method.
@override protected void publishresults(charsequence constraint, filterresults result) { final arraylist<car> filtered = (arraylist<car>) results.values; (int = 0, l = filtered.size(); < l; i++) { add(filtered.get(i)); } }
the method above works fine, when have 100 or entries. when entries thousands, ui thread hangs few seconds. thought move asynctask
, crashes. best way handle results without having ui hang?
code crashes (seems start, , crash in middle of loop:
@override protected void publishresults(charsequence constraint, filterresults result) { final arraylist<car> filtered = (arraylist<car>) results.values; new longoperation().execute(filtered); } private class longoperation extends asynctask<arraylist<car>, void, void> { @override protected void doinbackground(arraylist<car>... params) { (int = 0, l = params[0].size(); < l; i++) { add(params[0].get(i)); } return null; } @override protected void onpostexecute(void result) { notifydatasetchanged(); } } };
here crash message. using commonsware mergeadapter combine 2 adapters, maybe may issue?
e/androidruntime(22868): java.lang.illegalstateexception: content of adapter has changed listview did not receive notification. make sure content of adapter not modified background thread, ui thread. make sure adapter calls notifydatasetchanged() when content changes. [in listview(16908298, class android.widget.listview) adapter(class com.commonsware.cwac.merge.mergeadapter)]
you cannot manipulate adapter data in background thread. error says:
make sure content of adapter not modified background thread, ui thread
one solution have 2 representation of data, , when change swap between them. , make sure swapping on main thread.
Comments
Post a Comment