android - populating RecyclerView from AsyncTask fails and results in empty Screen -
trying populate data recyclerview
cloud, though output in main thread, takes time, decided add asynctask
load items ease , insert progressdialog
, seems code has no effect, getting empty screen.
but asynctask
getting executed, able log items in logcat, no idea why don't recyclerview. here code use , looking help:
public class bigboard extends actionbaractivity { private list<person> persons; private recyclerview rv; private rvadapter adapter; private string a,b; private progressdialog pr; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); parse.initialize(this, "app-id", "client-key"); setcontentview(r.layout.activity_big_board); loader abc = new loader(); abc.execute(); adapter = new rvadapter(persons); rv=(recyclerview)findviewbyid(r.id.rv); linearlayoutmanager llm = new linearlayoutmanager(this); rv.setlayoutmanager(llm); rv.sethasfixedsize(true); } private class loader extends asynctask<string, integer, string> { @override protected void onpreexecute() { pr = new progressdialog(bigboard.this); pr.setprogressstyle(progressdialog.style_spinner); pr.setindeterminate(true); pr.setcancelable(false); pr.setmessage("loading board"); pr.show(); super.onpreexecute(); } @override protected void onprogressupdate(integer... values) { super.onprogressupdate(values); } @override protected string doinbackground(string... urls) { initializedata(); initializeadapter(); return null; } @override protected void onpostexecute(string result) { pr.dismiss(); } private void initializedata(){ persons = new arraylist<>(); parsequery<parseobject> query = new parsequery<parseobject>("bigboard"); query.findinbackground(new findcallback<parseobject>() { public void done(list<parseobject> credentiallist, parseexception e) { if (e == null) { for(int i=0;i<credentiallist.size();i++) { a=credentiallist.get(i).getstring("location"); b=credentiallist.get(i).getstring("feed"); persons.add(new person(a,b)); log.d("out", "so val::------> " +a +b); } } else { log.d("score", "error: " + e.getmessage()); } adapter.notifydatasetchanged(); } }); } private void initializeadapter(){ rv.setadapter(adapter); } } }
place adapter.notifydatasetchanged();
or rv.setadapter(adapter);
onpostexecute.. since onopostexecute works on ui thread.
edit : create function inside adapter
public void updatepersons(list<person> persons) { this.persons = persons; notifydatasetchanged(); }
after filling list in onpostexecute call function list.
Comments
Post a Comment