android - Equivalent of nameList.add(name) in recylerview -


i used add item in listview this

            name name = new name("via button");             namelist.add(name);             madapter.notifydatasetchanged(); 

i know equivalent of in recyclerview. lot.

you can define recycler view adapter takes take list 1 of params...in case list...once have defined adapter can pass on list of class level adapter. once fetch data (through api call or other means) can add add data , call notify data set custom adapter. example:

// custructor of custom adapter public customadapter(list<name> mylist) {     this.mylist = mylist; }  //your class implementation public class myclass{ private arraylist<name> mylist = new arraylist<>(); customadapter myadapter; . . . public void init(){  //more code , init of components   myadapter = new customadapter(mylist);  recyclerview.setadapter(myadapter); }     //more codes //once receive data api call (maybe) name name = new name("via button");         mylist.add(name);  myadapter.notifydatasetchanged(); //more codes } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -