android - Issue on update data by notifyDataSetChanged in RecyclerView -
i used recycler view show list of data. called web service , data server , update current arraylist server data. how fill data in current arraylist.
maluotesdatas.clear(); maluotesdatas = (arraylist<billboarddata>) webservice.data; muotesadaptor.notifydatasetchanged();
and apply notifydatasetchanged() reflect in list of data doesn't reflect list. in maluotesdatas
shows updated data doesn't shows updated list of data.
after change
maluotesdatas.clear(); maluotesdatas.addall(res.data); muotesadaptor.notifydatasetchanged();
this works fine. surprising me, how works??, though both have updated data after web service call.
can me understand how can be.?
this class.
package com.mimran.aphorismus.models; import android.os.bundle; import android.support.v7.widget.recyclerview; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import com.mimran.aphorismus.r; import com.mimran.aphorismus.adapters.quotesadaptor; import java.util.arraylist; public class datafragment extends fragment { private recyclerview mrcvquotes; private quotesadaptor muotesadaptor; private arraylist<billboarddata> maluotesdatas; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { mrcvquotes = (recyclerview) links(r.id.rcv_quotes); muotesadaptor = new quotesadaptor(mcontext, maluotesdatas); mrcvquotes.setadapter(muotesadaptor); return inflater.inflate(r.layout.my_view, container, false); } public void webservicecall() { public void onresponse () { if (response.issuccess()) { maluotesdatas.clear(); //maluotesdatas = (arraylist<billboarddata>) res.data; maluotesdatas.addall(res.data); muotesadaptor.notifydatasetchanged(); } } } }
it doesn't work because don't add items proper instance of data collection.
adapter
initialized in constructor specific instance of data collection , it's working on time.
after this:
maluotesdatas = (arraylist<billboarddata>) webservice.data;
maluotesdatas
reference different collection adapter
's instance.
then:
muotesadaptor.notifydatasetchanged();
actually notify adapter changes in "old" data collection hasn't changed.
when use clear
, addall
works because work same instance , you're replacing items inside it.
Comments
Post a Comment