java - How to set Retrofit response body data in Listview -


in daata function try fetch data server. fetched, data cant set in arraylist

list<flowerlistmodel>flowerlistmodels=new arraylist<>(); 

cause want set flowerlistmodels data in floweradapter , show in listview

  public void daata() {     call<list<flowerlistdata>>listcall=apiinterface.getflowers();     listcall.enqueue(new callback<list<flowerlistdata>>() {         @override         public void onresponse(call<list<flowerlistdata>> call, response<list<flowerlistdata>> response) {             log.d("datacheck",new gson().tojson(response.body()));             list<flowerlistmodel>flowerlistmodels=new arraylist<>();            floweradapter floweradapter = new floweradapter(getapplicationcontext(),flowerlistmodels);             listview.setadapter(floweradapter);         }         @override         public void onfailure(call<list<flowerlistdata>> call, throwable t) {             toast.maketext(getapplicationcontext(), "error", toast.length_short).show();         }     }); } 

here flowerlistmodel class

package bdservers.com.schoolmanagement.model;  public class flowerlistmodel {      private string category;     private string instructions;     private string photo;     private string name;     private string price;      public flowerlistmodel(){}     public flowerlistmodel(string category, string instructions, string photo, string name,string price){         this.category=category;         this.instructions=instructions;         this.photo=photo;         this.name=name;        this.price=price;        }      public string getcategory() {         return category;     }      public void setcategory(string category) {         this.category = category;     }      public string getinstructions() {         return instructions;     }      public void setinstructions(string instructions) {         this.instructions = instructions;     }      public string getphoto() {         return photo;     }      public void setphoto(string photo) {         this.photo = photo;     }      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }     public string getprice() {         return price;     }     public void setprice(string price) {         this.price = price;     }  } 

you creating new empty list here: list<flowerlistmodel>flowerlistmodels=new arraylist<>();

you can try this:

    @override     public void onresponse(call<list<flowerlistdata>> call, response<list<flowerlistdata>> response) {         log.d("datacheck",new gson().tojson(response.body()));         floweradapter floweradapter = new floweradapter(getapplicationcontext(),response.body());         listview.setadapter(floweradapter);     } 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -