android - E/RecyclerView: No adapter attached; skipping layout with fragments -
this first application in android studio , can´t resolve error, need help, thanks.
e/recyclerview: no adapter attached; skipping layout e/recyclerview: no adapter attached; skipping layout
mainactivity
public class mainactivity extends appcompatactivity { private viewpager mpager; private slidingtablayout mtabs; private toolbar toolbar; private recyclerview recyclerview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); //toolbar toolbar= (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); //sliding tab mpager = (viewpager) findviewbyid(r.id.pager); mtabs= (slidingtablayout) findviewbyid(r.id.tabs); mpager.setadapter(new myadapter(getsupportfragmentmanager(),this)); mtabs.setdistributeevenly(true); mtabs.setcustomtabview(r.layout.tab_view, r.id.tabteks); mtabs.setbackgroundcolor(getresources().getcolor(r.color.colorprimary)); mtabs.setselectedindicatorcolors(getresources().getcolor(r.color.coloraccent)); mtabs.setviewpager(mpager); }
my adapter
public class myadapter extends fragmentpageradapter { private context mcontext; private string[] titles ={"overview","portofolio","team"}; int [] icons = new int []{r.mipmap.ic_adopcion, r.mipmap.ic_launcher, r.mipmap.ic_launcher}; private int heighticon; public myadapter(fragmentmanager fm, context c) { super(fm); mcontext=c; double scale=c.getresources().getdisplaymetrics().density; heighticon=(int)(30*scale+0.5f); } @override public fragment getitem(int position) { fragment frag=null; if (position==0){ frag = new overviewfragment(); } else if(position==1){ frag= new teamfragment(); } else if(position==2){ frag = new portofoliofragment(); } bundle b = new bundle(); b.putint("position", position); frag.setarguments(b); return frag; } @override public int getcount() { return titles.length; } @override public charsequence getpagetitle(int position) { drawable d = mcontext.getresources().getdrawable(icons[position]); d.setbounds(0,0,heighticon,heighticon); imagespan = new imagespan(d); spannablestring sp = new spannablestring(" "); sp.setspan(is,0,sp.length(), spanned.span_exclusive_exclusive); return (sp); }
itemadapter
public class itemadapter extends recyclerview.adapter<itemholder> { private list<perros> perroslist; public itemadapter(list<perros> perroslist){ this.perroslist = perroslist; } @override public itemholder oncreateviewholder(viewgroup parent, int viewtype) { view itemview = layoutinflater.from(parent.getcontext()) .inflate(r.layout.item_layout, parent, false); return new itemholder(itemview); } @override public void onbindviewholder(itemholder holder, int position) { perros item = perroslist.get(position); holder.txtcelebname.settext(item.getname()); holder.txtcelebmovie.settext(item.getfamousmovie()); picasso.with(holder.txtcelebname.getcontext()).load(item.getprofilephotolocation()).into(holder.profileimage); picasso.with(holder.txtcelebname.getcontext()).load(item.getimgsex()).into(holder.imgsex); } @override public int getitemcount() { return perroslist.size(); }
fragment
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment view rootview = inflater.inflate(r.layout.fragment_overview, container, false); //return inflater.inflate(r.layout.fragment_overview, container, false); recyclerview = (recyclerview) rootview.findviewbyid(r.id.recycler_view); recyclerview.setlayoutmanager(new linearlayoutmanager(getactivity())); mrequestqueue = mysingleton.getinstance().getrequestqueue(); array = new jsonobjectrequest(request.method.get, url, "", new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { log.d(tag, response.tostring()); itemadapter = new itemadapter(getperros(response)); recyclerview.setadapter(itemadapter); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { log.d(tag,error.tostring()); } }); mrequestqueue.add(array); return rootview; //return inflater.inflate(r.layout.fragment_overview, container, false); } private list<perros> getperros(jsonobject jsonobject){ list<perros> lista = new arraylist<>(); try { jsonarray array= jsonobject.getjsonarray("alumnos"); (int i=0; i<array.length(); i++){ jsonobject objeto = array.getjsonobject(i); perros perro = new perros(); perro.setname(objeto.getstring("nombre")); perro.setfamousmovie(objeto.getstring("direccion")); perro.setprofilephotolocation(img+objeto.getstring("rutaimagen")); perro.setimgsex(img+objeto.getstring("sexo")); lista.add(perro); } } catch (jsonexception e) { e.printstacktrace(); } return lista; }
you need set blank adapter before data in arrayadapter in oncreate() method. first of put below line in itemadapter in getitemcount() method.
return (null != perroslist ? perroslist.size() : 0);
Comments
Post a Comment