If you and I describe the following several things, then this I check out the bug solution may be able to solve your problem
1.setadapter on the onclick event
2. The adapter is written as standard after the optimization
3. The data is sometimes empty, sometimes can be adapted, as long as the time is empty, and then the data will not be able to fit
Workaround:
Idea: In the adapter to determine whether the data is empty, if it is empty on the new array to give it a value,
If not null, it is equal to the value passed in.
Procedure: Start by giving adapter the data source null, write a UpdateData method yourself
Direct update after click, Setadapter is null
Specific operation code:
**adapter Construction Method * * Public Governmentinstitutionadapter(Context Mcontext, list<governmentinstitutionbean> institutionbeanslist) { This. Mcontext = Mcontext;//Determine if it is empty if(Institutionbeanslist = =NULL) {institutionbeanslist =NewArraylist<governmentinstitutionbean> (); }Else{ This. institutionbeanslist = institutionbeanslist; } }//Write your own UpdateData method Public void Updateadapter(list<governmentinstitutionbean> institutionbeanslist) {if(Institutionbeanslist = =NULL) This. institutionbeanslist =NewArraylist<governmentinstitutionbean> ();Else This. institutionbeanslist = institutionbeanslist; This. notifydatasetchanged (); }
Specific steps in the activity:
SearchButton.Setonclicklistener (NewOnclicklistener () {//1.adapter Initialization, note that the data is nullGovernmentinstitutionadapter Adapter= NewGovernmentinstitutionadapter (Getapplicationcontext (),NULL); @Override Public voidOnClick (View v) {....... .... //2. Calling the Updateadapter method is equivalent to fitting aAdapter.Updateadapter (Dynamic Data source to be adapted);... //3. Last SetadapterListview.Setadapter (adapter);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java.lang.IllegalStateException:Observer Adapterdatasetobserver is not register setadapter null pointer