android - Empty RecyclerView from JSON to Fragment -
i'm new android development , first real app. did lots of research can't work.
i'm trying send json data recyclerview in fragment displays blank screen, no error.
here's code:
fragment public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { string endpoints = "{\"access\": {\"token\":....; arraylist<hashmap<string, string>> jsonlist; view rootview = inflater.inflate(r.layout.fragment_overview, container, false); jsonlist = endpointsparser.parsejson(endpoints); recyclerview recyclerview = (recyclerview)rootview.findviewbyid(r.id.overviewrv); recyclerview.setlayoutmanager(new linearlayoutmanager(getactivity())); endpointsadapter endpointsadapter = new endpointsadapter(getactivity(),jsonlist); recyclerview.setadapter(endpointsadapter); return rootview; } parser public class endpointsparser extends activity{ public static final string publicurl = "publicurl"; public static final string region = "region"; public static final string type = "type"; public static final string name = "name"; public static arraylist<hashmap<string, string>> parsejson(string endpoints){ arraylist<hashmap<string, string>> jsonlist = new arraylist<hashmap<string, string>>(); try { endpoints endpoint = new endpoints(); jsonobject keystone = new jsonobject(endpoints); jsonobject access = keystone.getjsonobject("access"); jsonarray servicecatalog = access.getjsonarray("servicecatalog"); (int = 0; < servicecatalog.length(); i++) { jsonobject objsvc = servicecatalog.getjsonobject(i); jsonarray endpointsarray = objsvc.getjsonarray("endpoints"); endpoint.setname(objsvc.getstring("name")); endpoint.settype(objsvc.getstring("type")); (int j = 0; j < 1; j++) { jsonobject objept = endpointsarray.getjsonobject(j); endpoint.setregion(objept.getstring("region")); endpoint.setpublicurl(objept.getstring("publicurl")); } hashmap<string, string> map = new hashmap<string, string>(); map.put(name, endpoint.getname()); map.put(type, endpoint.gettype()); map.put(region, endpoint.getregion()); map.put(publicurl, endpoint.getpublicurl()); jsonlist.add(map); } } catch (jsonexception e) { log.d("errorinitjson", e.tostring()); e.printstacktrace(); } return jsonlist; } adapter public class endpointsadapter extends recyclerview.adapter<endpointlistrowholder> { arraylist<hashmap<string, string>> endpointslist = new arraylist<hashmap<string, string>>(); public static final string publicurl = "publicurl"; public static final string region = "region"; public static final string type = "type"; public static final string name = "name"; private context mcontext; public endpointsadapter(context context, arraylist<hashmap<string, string>> endpointslist) { this.endpointslist = endpointslist; this.mcontext = context; } @override public endpointlistrowholder oncreateviewholder(viewgroup viewgroup, int i) { view v = layoutinflater.from(viewgroup.getcontext()).inflate(r.layout.endpoint_list, null); endpointlistrowholder mh = new endpointlistrowholder(v); return mh; } @override public void onbindviewholder(endpointlistrowholder endpointlistrowholder, int i) { endpointlistrowholder.name.settext(endpointslist.get(i).get(name)); endpointlistrowholder.type.settext(endpointslist.get(i).get(type)); endpointlistrowholder.region.settext(endpointslist.get(i).get(region)); endpointlistrowholder.url.settext(endpointslist.get(i).get(publicurl)); } @override public int getitemcount() { return (null != endpointslist ? endpointslist.size() : 0); } } class endpointlistrowholder extends recyclerview.viewholder { protected textview name; protected textview type; protected textview region; protected textview url; public endpointlistrowholder(view view) { super(view); this.name = (textview) view.findviewbyid(r.id.name); this.type = (textview) view.findviewbyid(r.id.type); this.region = (textview) view.findviewbyid(r.id.region); this.url = (textview) view.findviewbyid(r.id.url); } }
from debugger can see list correctly sent recyclerview.setadapter on gets null. seems it's 90% working, i'd appreciate lot make 100%. ideas?
the code above working, issue xml file
Comments
Post a Comment