java - Get data in my RecyclerView -
i started work retrofit. in application have 1 recyclerview 2 viewholder's, trying data models, in logs coming type:
@override public void onresponse(call<dropdown> call, response<dropdown> response) { dropdown jsonresponse = response.body(); log.d("type",jsonresponse.getform().getmgroupss().get(1).getmcontrols().get(2).gettitle()+""); adapter = new dataadapter(response.body()); recyclerview.setadapter(adapter); }
how can display type in recyclerview, if there few types? next message:
09-13 09:20:40.958 2798-2798/com.random.secondproject e/recyclerview: no adapter attached; skipping layout
dataadapter:
public class dataadapter extends recyclerview.adapter<recyclerview.viewholder> { public static final string type_textview = "0"; public static final string type_editview = "1"; private dropdown mlist; public dataadapter(dropdown list) { this.mlist = list; } @override public recyclerview.viewholder oncreateviewholder(viewgroup parent, int viewtype) { view view; switch (viewtype) { case 0: view = layoutinflater.from(parent.getcontext()).inflate(r.layout.text_numeric, parent, false); return new numericviewholder(view); case 1: view = layoutinflater.from(parent.getcontext()).inflate(r.layout.drop_down_options, parent, false); return new dropdownviewholder(view); } return null; } @override public void onbindviewholder(recyclerview.viewholder holder, int position) { dropdown object = mlist.get(position); if (object != null) { switch (object.gettitle()){ case type_textview: ((numericviewholder) holder).title.settext(string.valueof(object.gettitle())); break; case type_editview: ((dropdownviewholder) holder).title_options.settext(string.valueof(object.gettitle())); break; } } } @override public int getitemcount() { if (mlist == null) return 0; return mlist.size(); } @override public int getitemviewtype(int position) { dropdown object = mlist.get(position); if (object.gettitle().equals("drop_down_options")) return 0; else return 1; } public class numericviewholder extends recyclerview.viewholder { private textview title; public numericviewholder(view itemview) { super(itemview); title = (textview) itemview.findviewbyid(r.id.title); } } public class dropdownviewholder extends recyclerview.viewholder { private edittext title_options; public dropdownviewholder(view itemview) { super(itemview); title_options = (edittext) itemview.findviewbyid(r.id.title_options); }
as can see, i'm going take 2 types (textview , edittext) write few ways model(array think). example, wrote in log.d .
everything seem ok me in adapter. try call recyclerview.invalidate(). idea draw recyclerview before calling onresponse method. thus, have empty view. invalidate() method try redraw view.
Comments
Post a Comment