android - No data inside the custom adapter -


this code slidenerd tutorial recyclerview im trying bind data recyclerview using getdata function

public static list<information> getdata() {     list<information> menudata=new arraylist<>();     int[] icons={r.drawable.ic_bluetooth,r.drawable.ic_crosshairs_gps,r.drawable.ic_laptop,r.drawable.ic_remote};     string[] titles={"bluetooth","gps","laptop","remote"};      for(int i=0;i<titles.length&&i<icons.length;i++)     {         information current =new information();         current.iconid=icons[i];         current.title=titles[i];         menudata.add(current);     }      return menudata; } 

last iteration in loop shows 4 items in menudata list iadapter shows data size=0

enter image description here

informationadapter

public class informationadapter extends recyclerview.adapter<informationadapter.infoviewholder> {      private layoutinflater inflator;     list<information> data=collections.emptylist();      public informationadapter(context context, list<information> data) {        inflator= layoutinflater.from(context);     }      @override     public infoviewholder oncreateviewholder(viewgroup parent, int i) {        view view= inflator.inflate(r.layout.custom_row,parent,false);          infoviewholder holder=new infoviewholder(view);          return holder;     }      @override     public void onbindviewholder(infoviewholder holder, int position) {         information current=data.get(position);         holder.title.settext(current.title);         holder.icon.setimageresource(current.iconid);      }      @override     public int getitemcount()     {          return data.size();     }     class infoviewholder extends recyclerview.viewholder     {       textview title;         imageview icon;          public infoviewholder(view itemview) {              super(itemview);             title= (textview) itemview.findviewbyid(r.id.list_text);            icon= (imageview) itemview.findviewbyid(r.id.text_icon);         }     } } 

the problem didnt reference list of data passed in constructor therefore data list empty:

 public informationadapter(context context, list<information> data) {    inflator= layoutinflater.from(context); } 

it should be

 public informationadapter(context context, list<information> data) {    inflator= layoutinflater.from(context);    this.data = data; } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -