android - ListView Inside a RecyclerView -
i creating listview inside recyclerview. populating recyclerview data fetched online. recyclerview populating properly. want populate listview @ run time when button clicked. defining onclicklistener button , on button click getting data , populating adapter set listview. data not reflecting in listview.
onclicklistener button
holder.arrow_up.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { new loadclothes().execute(order.getorderid()); } });
asynctask loading details listview
private class loadclothes extends asynctask<string, void, string> { @override protected void onpreexecute() { super.onpreexecute(); } @override protected string doinbackground(string... strings) { string string = ""; try { request request = new request.builder() .url(orderclothes) .addheader("token", baseapplication.gettoken()) .addheader("orderid", strings[0]) .build(); response response = client.newcall(request).execute(); string = response.body().string(); logger.d(string); } catch (ioexception e) { e.printstacktrace(); } return string; } @override protected void onpostexecute(string string) { super.onpostexecute(string); logger.d(string); gson gson = new gson(); type type = new typetoken<list<orderedcloth>>() { }.gettype(); cloths = gson.fromjson(string, type); viewholder.listview.setvisibility(listview.visible); customlistorderadapter adapter = new customlistorderadapter(context, cloths); viewholder.listview.setadapter(adapter); adapter.notifydatasetchanged(); } }
are sure want that? seems design pattern problem. if going show additional data fetched http request, better way activity details.
however, i think problem "viewholder", getting variable?
a simple way solve seems passing listview asynctask:
private class loadclothes extends asynctask<string, void, string> { private listview listview; public loadcloathes(listview listview) { this.listview = listview; } //... @override protected void onpostexecute(string string) { super.onpostexecute(string); //mostly same //make sure somehow listview still available listview.setadapter... } }
then run asynctask:
new loadclothes(listview).execute(order.getorderid());
as can see asynctask can take params in constructor, arguments in execute()
method support asynctask cycle, still java class.
Comments
Post a Comment