android - RecyclerView with firebase remains blank sometimes, but shows items sometimes -
this question has answer here recyclerview not updated new data not working me. dont understand why recyclerview shows items won't show. i'm using 4 framents viewpager. not internet issue since other fragments display data internet. have tried using firebaserecycler adapter , custom adapter , listview in place of recyclerview. here code fragement. please me.
public class fragmenttips extends fragment { public recyclerview recyclerlistview; public myrecycleradapter myadapter; databasereference databasereference; textview loading; view v; swiperefreshlayout refresher; list<model> listposts = new arraylist<>(); @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) { v = inflater.inflate(r.layout.activity_home, container, false); databasereference = firebasedatabase.getinstance().getreference(); creatinglayouts(); final nativeexpressadview adview = (nativeexpressadview) v.findviewbyid(r.id.adview); adview.loadad(new adrequest.builder().build()); adview.setadlistener(new adlistener() { @override public void onadloaded() { adview.setvisibility(view.visible); } }); return v; } public void creatinglayouts() { refresher = (swiperefreshlayout) v.findviewbyid(r.id.refresher); //refresher.setrefreshing(true); refresher.setcolorschemeresources(r.color.blue, r.color.lightblue, r.color.deeppurple, r.color.purple, r.color.pink, r.color.orange, r.color.red); refresher.setonrefreshlistener(new swiperefreshlayout.onrefreshlistener() { @override public void onrefresh() { if (myadapter != null) { updateadapter(); } } }); loading = (textview) v.findviewbyid(r.id.loading); recyclerlistview = (recyclerview) v.findviewbyid(r.id.recycler); recyclerlistview.sethasfixedsize(false); recyclerlistview.setlayoutmanager(new linearlayoutmanager(getactivity())); myadapter = new myrecycleradapter(getcontext()); updateadapter(); recyclerlistview.setadapter(myadapter); } //update adapter public void updateadapter() { listposts.clear(); databasereference.child("winbet").addchildeventlistener(new childeventlistener() { @override public void onchildadded(datasnapshot datasnapshot, string s) { listposts.add(datasnapshot.getvalue(model.class)); displayposts(listposts); } @override public void onchildchanged(datasnapshot datasnapshot, string s) { } @override public void onchildremoved(datasnapshot datasnapshot) { } @override public void onchildmoved(datasnapshot datasnapshot, string s) { } @override public void oncancelled(databaseerror databaseerror) { toast.maketext(getcontext(), "canceled", toast.length_short).show(); } }); } public void displayposts(list<model> ls) { refresher.setrefreshing(false); loading.setvisibility(view.gone); recyclerlistview.setvisibility(view.visible); myadapter.setdata(ls); myadapter.notifydatasetchanged(); } }
thank guys. found solution finally. isn't related code. if ever faces such issue. problem was using free firebase plan , connections allowed 100, reaching peak since have many users. solution upgrade
Comments
Post a Comment