title: Android - looping for getJsonObject goes wrong
body: <p>I want to create <code>jsonObject</code> with output,</p>
  
  <p>this is the code i used to get <code>jsonObject</code> :</p>
  
  <pre><code>public JSONObject getJsonObject() {
      JSONObject obj = new JSONObject();
      try {
          obj.put("id", id);
          obj.put("nilai", ratingStar);
      } catch (JSONException e) {
          e.printStackTrace();
      }
      return obj;
  }
  </code></pre>
  
  <p>but when i loop the json using this code inside button.onClick :</p>
  
  <pre><code> int size = adapter3.getCount();
   StringBuilder b = new StringBuilder();
   JSONArray jArray = new JSONArray();
   for (int i=0;i&lt;=size;i++){
        b.append(jArray.put(adapter3.getItem(i).getJsonObject()));
   }
   TextView Star = (TextView)findViewById(R.id.test);
   Star.setText(b.toString());
  </code></pre>
  
  <p>why the output goes wrong?</p>
  
  <p>the output gonna be like :</p>
  
  <pre><code>[{"id":"1","nilai":"1"},
  [{"id":"1","nilai":"1"},
  [{"id":"2","nilai":"1"},
  [{"id":"1","nilai":"1"},
  [{"id":"2","nilai":"1"},
  [{"id":"3","nilai":"1"},
  [{"id":"1","nilai":"1"},
  [{"id":"2","nilai":"1"},
  [{"id":"3","nilai":"1"},
  [{"id":"4","nilai":"1"},
  [{"id":"1","nilai":"1"},
  [{"id":"2","nilai":"1"},
  [{"id":"3","nilai":"1"},
  [{"id":"4","nilai":"1"},
  [{"id":"5","nilai":"1"},
  </code></pre>
  
  <p>it's like the output repeating the id from <code>1 | 1_2 | 1_2_3 | 1_2_3_4 | 1_2_3_4_5</code></p>
  
  <p>did i doing something wrong? why the output is repeating like that</p>
  
  <p><strong>EDIT</strong></p>
  
  <p><code>Pertanyaan.java</code></p>
  
  <pre><code>public class Pertanyaan {
  private String id;
  private float ratingStar;
  private String ask;
  
  Pertanyaan(String id, int ratingStar, String ask) {
      this.id = id;
      this.ratingStar = ratingStar;
      this.ask = ask;
  }
  
  public String getId() {
      return id;
  }
  
  float getRatingStar() {
      return ratingStar;
  }
  
  void setRatingStar(float ratingStar) {
      this.ratingStar = ratingStar;
  }
  
  public String getAsk() {
      return ask;
  }
  
  public JSONObject getJsonObject() {
      JSONObject obj = new JSONObject();
      try {
          obj.put("id", id);
          obj.put("nilai", ratingStar);
      } catch (JSONException e) {
          e.printStackTrace();
      }
      return obj;
  }
  }
  </code></pre>
  
  <p><code>PertanyaanAdapter.java</code></p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>class PertanyaanAdapter extends ArrayAdapter&lt;Pertanyaan&gt; {
  
      private AppCompatActivity activity;
      private List&lt;Pertanyaan&gt; movieList;
  
      PertanyaanAdapter(AppCompatActivity context, int resource, List&lt;Pertanyaan&gt; objects) {
          super(context, resource, objects);
          this.activity = context;
          this.movieList = objects;
      }
  
      @Override
      public Pertanyaan getItem(int position) {
          return movieList.get(position);
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          ViewHolder holder;
          LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
  
          if (convertView == null) {
              convertView = inflater.inflate(R.layout.item_listview, parent, false);
              holder = new ViewHolder(convertView);
              convertView.setTag(holder);
  
          } else {
              holder = (ViewHolder) convertView.getTag();
              //holder.ratingBar.getTag(position);
          }
  
          holder.ratingBar.setOnRatingBarChangeListener(onRatingChangedListener(position));
  
          holder.ratingBar.setTag(position);
          holder.ratingBar.setRating(getItem(position).getRatingStar());
          holder.movieName.setText(getItem(position).getAsk());
          holder.id.setText(getItem(position).getId());
  
          return convertView;
      }
  
      private RatingBar.OnRatingBarChangeListener onRatingChangedListener(final int position) {
          return new RatingBar.OnRatingBarChangeListener() {
              @Override
              public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
                  Pertanyaan item = getItem(position);
                  assert item != null;
                  item.setRatingStar(v);
                  Log.i("Adapter", "star: " + v);
              }
          };
      }
  
      private static class ViewHolder {
          private RatingBar ratingBar;
          private TextView movieName;
          private TextView id;
  
          ViewHolder(View view) {
              ratingBar = (RatingBar) view.findViewById(R.id.rate_img);
              movieName = (TextView) view.findViewById(R.id.text);
              id = (TextView) view.findViewById(R.id.textid);
          }
      }
  }
  </code></pre>