How to set all values in listview android -


i have created listview. values retrieved json response last values displayed in list.what displaying values in list view.

 sixfragment.movielist = new arraylist<movie1>();   (int i1 = 0; i1 < jsonarray3.length(); i1++) {      try {          jsonobject jsonobject = jsonarray3.getjsonobject(i1);          review_rating = jsonobject.optstring("review_rating").tostring();          username_rate = jsonobject.optstring("username").tostring();          review_title = jsonobject.optstring("review_title").tostring();          review_desc = jsonobject.optstring("review_desc").tostring();          sleep = jsonobject.optstring("sleep").tostring();          location = jsonobject.optstring("location").tostring();          service = jsonobject.optstring("service").tostring();          rooms = jsonobject.optstring("rooms").tostring();          cleanliness = jsonobject.optstring("cleanliness").tostring();          userimage1 = jsonobject.optstring("user_image").tostring();           movie1 movie = new movie1();                       movie.setrate_userimage(userimage1);                     movie.setreview_rating(review_rating);                     movie.setusername_rate(username_rate);                     movie.setreview_title(review_title);                     movie.setreview_desc(review_desc);                     movie.setsleep(sleep);                     movie.setlocation(location);                     movie.setservice(service);                     movie.setraterooms(rooms);                     movie.setcleanliness(cleanliness);                      sixfragment.movielist.add(movie);                  } catch (jsonexception e) {                     e.printstacktrace();                 }              } 

this fragment page:

public class sixfragment extends fragment{     public static string userimage;     public static string review_rating;     public static string username_rate;     public static string  review_title;     public static string review_desc;     public static string  sleep;     public static string  location;     public static string  service;     public static string  rooms;     public static string  cleanliness;     public static arraylist stringarray;     public static arraylist<movie1> movielist= new arraylist<movie1>();;      listview listview;     reviewadapter reviewadapter;      public sixfragment() {         // required empty public constructor     }      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         // inflate layout fragment         view v= inflater.inflate(r.layout.fragment_six, container, false);         listview list=(listview)v.findviewbyid(r.id.six_listview);            return v;     }  } 

this logcat error`

  e/androidruntime: fatal exception: main   process: com.airstar.abservetech.airstar, pid: 27390                                                                                      java.lang.nullpointerexception                                                                                          @ com.airstar.abservetech.adapter.reviewadapter.getcount(reviewadapter.java:160)                                                                                          @ android.widget.listview.setadapter(listview.java:488)                                                                                          @ com.airstar.abservetech.airstar.sixfragment.oncreateview(sixfragment.java:75)                                                                                              @ android.support.v4.app.fragment.performcreateview(fragment.java:1974)                                                                              @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1067)                                                                              @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1252)                                                                              @ android.support.v4.app.backstackrecord.run(backstackrecord.java:742)                                                                              @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1617)                                                                              @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:570)                                                                              @ android.support.v4.app.fragmentpageradapter.finishupdate(fragmentpageradapter.java:141) 

`

review adapter

    public class reviewadapter extends baseadapter {     private final list<movie1> movieitems;     public sixfragment context;      onefragment fragment;     bitmap bitmap;     public reviewadapter(sixfragment context, list<movie1> movieitems) {         this.context = context;         this.movieitems = movieitems;         this.fragment=fragment;     }      public view getview(int position, view convertview, viewgroup parent) {          if (convertview == null) {             layoutinflater inflater = layoutinflater.from(parent.getcontext());             convertview = inflater.inflate(r.layout.fragment_sixlist,parent,false);              circleimageview profile_image = (circleimageview) convertview.findviewbyid(r.id.profile_image);             textview rate_username = (textview) convertview.findviewbyid(r.id.rate_username);             ratingbar ratingbar = (ratingbar) convertview.findviewbyid(r.id.ratingbar);             textview rate_title = (textview) convertview.findviewbyid(r.id.rate_title);             textview rate_description = (textview) convertview.findviewbyid(r.id.rate_description);             ratingbar ratingbar_sleep = (ratingbar) convertview.findviewbyid(r.id.ratingbar_sleep);             ratingbar ratingbar_location = (ratingbar) convertview.findviewbyid(r.id.ratingbar_location);             ratingbar ratingbar_service = (ratingbar) convertview.findviewbyid(r.id.ratingbar_service);             ratingbar ratingbar_clearness = (ratingbar) convertview.findviewbyid(r.id.ratingbar_clearness);             ratingbar ratingbar_rooms = (ratingbar) convertview.findviewbyid(r.id.ratingbar_rooms);              final movie1 m = movieitems.get(position);   //            glide.with(context) //                    .load(m.getrate_userimage()) //                    .diskcachestrategy(diskcachestrategy.all) //                    .into(profile_image);             url url = null;             string image=m.getrate_userimage();             try {                 url = new url(image);                 inputstream = null; //                bitmap bitmap = bitmapfactory.decodestream(is);                 //create imageview dynamically                  glide.with(context).load(string.valueof(url)).into(profile_image);              } catch (malformedurlexception e) {                 e.printstacktrace();             }             //glide.with(context).load(string.valueof(url)).into(profile_image);              if (m.getusername_rate()!=null)             {                 if (!m.getusername_rate().equals("null"))                 {                     rate_username.settext(m.getusername_rate());                 }}              if (m.getreview_rating()!=null)             {                 if (!m.getreview_rating().equals("null"))                 {                     ratingbar.setrating(float.parsefloat(m.getreview_rating()));                  }}               if (m.getsleep()!=null)             {                 if (!m.getsleep().equals("null"))                 {                     ratingbar_sleep.setrating(float.parsefloat(m.getsleep()));                  }}           }           return convertview;     }      @override     public int getcount() {         return movieitems.size();     }      @override     public object getitem(int location) {         return movieitems.get(location);     }      @override     public long getitemid(int position) {         return position;     } } 

in fragment make list static:

public class sixfragment extends fragment{        // code //------------do this------------------///  public static list<movie1> movielist = new arraylist<movie1>();   public sixfragment() {     // required empty public constructor }  //your code  } 

rest of code in fragment is.

change json loop :

sixfragment.movielist = new arraylist<movie1>();     (int i1 = 0; i1 < jsonarray3.length(); i1++) {         try {             jsonobject jsonobject = jsonarray3.getjsonobject(i1);             review_rating = jsonobject.optstring("review_rating").tostring();             username_rate = jsonobject.optstring("username").tostring();             review_title = jsonobject.optstring("review_title").tostring();             review_desc = jsonobject.optstring("review_desc").tostring();             sleep = jsonobject.optstring("sleep").tostring();             location = jsonobject.optstring("location").tostring();             service = jsonobject.optstring("service").tostring();             rooms = jsonobject.optstring("rooms").tostring();             cleanliness = jsonobject.optstring("cleanliness").tostring();             userimage1 = jsonobject.optstring("user_image").tostring();              movie1 movie = new movie1();               movie.setrate_userimage(userimage1);             movie.setreview_rating(review_rating);             movie.setusername_rate(username_rate);             movie.setreview_title(review_title);             movie.setreview_desc(review_desc);             movie.setsleep(sleep);             movie.setlocation(location);             movie.setservice(service);             movie.setraterooms(rooms);             movie.setcleanliness(cleanliness);              sixfragment.movielist.add(movie);          } catch (jsonexception e) {             e.printstacktrace();         }      } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -