How to set all values in listview android

sri

I have created a listview. All values are retrieved from the json response but only the last values were displayed in the list.what to do for displaying the all values in list view.

 SixFragment.movieList = new ArrayList<Movie1>();

 for (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 is my 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 the layout for this 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
                                                                                         at com.airstar.abservetech.adapter.Reviewadapter.getCount(Reviewadapter.java:160)
                                                                                         at android.widget.ListView.setAdapter(ListView.java:488)
                                                                                         at com.airstar.abservetech.airstar.SixFragment.onCreateView(SixFragment.java:75)
                                                                                             at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
                                                                             at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
                                                                             at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
                                                                             at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
                                                                             at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
                                                                             at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
                                                                             at 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 is = 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;
    }
}
Janki Gadhiya

In Your Fragment make your list static:

public class SixFragment extends Fragment{

      // Your code
//------------DO THIS------------------///

public static List<Movie1> movieList = new ArrayList<Movie1>();


public SixFragment() {
    // Required empty public constructor
}

//Your code

}

Rest of the code in your fragment will be as it is.

Change your JSON loop like this :

SixFragment.movieList = new ArrayList<Movie1>();
    for (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();
        }

    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to get all values of particular TextView of listView? -Android

android how to set border in listview

How to display a listview by comparing values in android

Android - How to filter a listview on multiple values?

How to get all the TextView value in listview in android?

android: How to remove listview all items with SimpleAdapter

How to set space between listView Items in Android

How to set Adapter for listview with image in Android

How to set up a custom ListView in a Fragment (Android)?

Unable to parse all values of XML to Custom ListView used in fragment, android?

How to set all values of an object to null in JavaScript?

How to set all formik values at once?

How to set "all values" as default in a multiple select?

How extract all values for one set of key

Duplicate values in listview in android

Android ListView not showing at all

Set CheckBox in ListView Android

How To store json values in a set of arrays in android

How to set values in cell to write in Android Studio

Android How to set Flags global for all Activities

How to set blur image in android for all version?

android how to set buttons in layout for all resolution

How to get the values of radio buttons from Custom Listview in Android?

Android: how to get values from strings.xml into listview?

How to get values from selected row in android listview?

How to get values from clicking listview item on Android? (NullException error)

In Android, how can I set a ListView item's height and width?

How to set drawable variable with ArrayAdapter to display it in ListView in android

Android: How to set the json data from Volley into the ListView?