title: Send recycler view data into a json
body: <p><a href="https://i.stack.imgur.com/VgosB.png" rel="nofollow noreferrer">Attendance Screen</a></p>
  
  <p>I am creating an application for Student Attendance I get data from Server as students details, Now I want to get values of radio present(green) or absent(red) with admission no how can I do this.
  Sorry for my English</p>
  
  <p>Here is the JSON format which I am going to send back to the server as attendance details</p>
  
  <pre><code>{
  "Date": "",
  "ClassRSN": "",
  "SectionRSN": "",
  "SessionRSN": "",
  "Studentdetails": [
      {
          "AdmissionID": "",
          "Attendance": ""
      }
  ]}
  </code></pre>
  
  <p>I am unable to iterate every value</p>
  
  <p>recyclerView class</p>
  
  <pre><code>public class StudentDetailsAdapter extends RecyclerView.Adapter&lt;StudentDetailsAdapter.ViewHolder&gt; {
  private Context context;
  Integer attendance;
  
  
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; StudentDetailList;
  
  public StudentDetailsAdapter(Context context, ArrayList&lt;HashMap&lt;String, String&gt;&gt; Studetails) {
      this.context = context;
      StudentDetailList = Studetails;
      Log.e("MD", "" + Studetails);
  }
  
  
  @Override
  public StudentDetailsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View itemView = LayoutInflater.from(context).inflate(R.layout.single_row_student_details, parent, false);
      return new StudentDetailsAdapter.ViewHolder(itemView);
  
  }
  
  @Override
  public void onBindViewHolder(StudentDetailsAdapter.ViewHolder holder, final int position) {
  
      if (position % 2 == 1) {
          holder.itemView.setBackgroundColor(Color.parseColor("#FFFFFF"));
  
      } else {
          holder.itemView.setBackgroundColor(Color.parseColor("#FFFAF8FD"));
  
      }
  
      holder.tvrollno.setText(StudentDetailList.get(position).get("stu_no"));
      holder.tvname.setText(StudentDetailList.get(position).get("stu_name"));
  
      if (holder.rdBtnPresent.isChecked()) {
          attendance = 1;
      } else {
          attendance = 0;
      }
      try {
          // Creating JSONObject from String
          JSONObject jsonObjMain = new JSONObject(ConstantClass.myjsonstring);
          Log.e("jsonObjMain", "jsonObjMain" + jsonObjMain);
          jsonObjMain.put("Date", "30-11-2018");
          jsonObjMain.put("ClassRSN", "1");
          jsonObjMain.put("SectionRSN", "1");
          jsonObjMain.put("SessionRSN", "13");
  
  
          JSONArray quesans = new JSONArray(jsonObjMain.getString("Studentdetails"));
          for (int i = 0; i &lt; StudentDetailList.size(); i++) {
              JSONObject studata = quesans.getJSONObject(i);
              studata.put("AdmissionID", StudentDetailList.get(position).get("stu_no"));
              studata.put("Attendance",StudentDetailList.get(position).attendance);
  
          }
  
  
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  }
  
  
  @Override
  public int getItemCount() {
  
      return StudentDetailList.size();
  
  }
  
  public class ViewHolder extends RecyclerView.ViewHolder {
      TextView tvrollno, tvname;
      RadioButton rdBtnPresent, rdBtnAbsent;
  
      public ViewHolder(View itemView) {
          super(itemView);
  
          tvrollno = (TextView) itemView.findViewById(R.id.tv_rollno);
          tvname = (TextView) itemView.findViewById(R.id.tv_name);
          rdBtnPresent = (RadioButton) itemView.findViewById(R.id.attendance_present);
          rdBtnAbsent = (RadioButton) itemView.findViewById(R.id.attendance_absent);
  
  
      }
  }}
  </code></pre>
  
  <p>MainActivity</p>
  
  <pre><code>public class Attendance extends AppCompatActivity {
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; StudentList = new ArrayList&lt;&gt;();
  Calendar myCalendar1;
  RecyclerView rdrecyclerView;
  DatePickerDialog.OnDateSetListener date1;
  EditText etAttDAte;
  Spinner classpinner, sectionspinner;
  List&lt;SpinnerBean&gt; block;
  Button btnGo;
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; StudentDetailsList = new ArrayList&lt;&gt;();
  LinearLayout LL_studeatils;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_class);
  
      SetIDs();
      SpinnerData();
  
  
      InVokeDatePicker();
      getSystemDate();
  }
  
  public void InVokeDatePicker() {
      myCalendar1 = Calendar.getInstance();
  
      date1 = new DatePickerDialog.OnDateSetListener() {
  
          @Override
          public void onDateSet(DatePicker view, int year, int monthOfYear,
                                int dayOfMonth) {
              // TODO Auto-generated method stub
              myCalendar1.set(Calendar.YEAR, year);
              myCalendar1.set(Calendar.MONTH, monthOfYear);
              myCalendar1.set(Calendar.DAY_OF_MONTH, dayOfMonth);
              updateLabel1();
          }
  
      };
  
  
      etAttDAte.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              new DatePickerDialog(Attendance.this, date1, myCalendar1
                      .get(Calendar.YEAR), myCalendar1.get(Calendar.MONTH),
                      myCalendar1.get(Calendar.DAY_OF_MONTH)).show();
          }
      });
  
  }
  
  private void updateLabel1() {
      String myFormat = "dd/MM/yyyy"; //In which you need put here
      SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
  
      etAttDAte.setText(sdf.format(myCalendar1.getTime()));
  
  }
  
  public void getSystemDate() {
      Date c = Calendar.getInstance().getTime();
      System.out.println("Current time =&gt; " + c);
  
      SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
      String formattedDate = df.format(c);
      etAttDAte.setText(formattedDate);
  }
  
  public void SpinnerData() {
      final List&lt;SpinnerBean&gt; dist = UtilityClass.getAllDistrict(Attendance.this);
      classpinner.setAdapter(new StateListAdapter(Attendance.this, dist));
  
      classpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
              SpinnerBean bean = (SpinnerBean) adapterView.getItemAtPosition(i);
              //Toast.makeText(getApplicationContext(), dist.get(i).getId(), Toast.LENGTH_LONG).show();
              ConstantClass.GetClass = dist.get(i).getId();
              block = UtilityClass.getDistricWiseBlock(Attendance.this, dist.get(i).getId());
              sectionspinner.setAdapter(new StateListAdapter(Attendance.this, block));
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; adapterView) {
              // DO Nothing here
          }
      });
      sectionspinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
              SpinnerBean bean = (SpinnerBean) adapterView.getItemAtPosition(i);
  
              //  Toast.makeText(getApplicationContext(), block.get(i).getId(), Toast.LENGTH_LONG).show();
              ConstantClass.GetSection = block.get(i).getId();
  
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; adapterView) {
              // DO Nothing here
          }
      });
  }
  
  public void SetIDs() {
      rdrecyclerView = (RecyclerView) findViewById(R.id.recView);
      etAttDAte = (EditText) findViewById(R.id.attendance_date);
      classpinner = (Spinner) findViewById(R.id.spinner_class);
      sectionspinner = (Spinner) findViewById(R.id.spinner_section);
      btnGo = (Button) findViewById(R.id.btn_go);
      LL_studeatils = (LinearLayout) findViewById(R.id.LL_studetailsView);
  
      btnGo.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              StudentDetailsList.clear();
              LL_studeatils.setVisibility(View.VISIBLE);
              new SendPostRequest().execute();
          }
      });
  }
  
  class SendPostRequest extends AsyncTask&lt;String, Void, String&gt; {
  
      protected void onPreExecute() {
      }
  
      protected String doInBackground(String... arg0) {
  
          try {
  
              java.net.URL url = new URL("http://mindfacttech.com/api/SchoolERPAPITemp/BL/StudentManager.php"); // here is your URL path
              Log.e("url", "" + url);
  
              JSONObject postDataParams = new JSONObject();
              postDataParams.put("ClassRSN", ConstantClass.GetClass);
              postDataParams.put("SectionRSN", ConstantClass.GetSection);
              postDataParams.put("studentlist", "yes");
              Log.e("postDataParams", "" + postDataParams);
  
  
              HttpURLConnection conn = (HttpURLConnection) url.openConnection();
              conn.setReadTimeout(15000 /* milliseconds */);
              conn.setConnectTimeout(15000 /* milliseconds */);
              conn.setRequestMethod("POST");
              conn.setDoInput(true);
              conn.setDoOutput(true);
  
              OutputStream os = conn.getOutputStream();
              BufferedWriter writer = new BufferedWriter(
                      new OutputStreamWriter(os, "UTF-8"));
              writer.write(getPostDataString(postDataParams));
  
              writer.flush();
              writer.close();
              os.close();
  
              int responseCode = conn.getResponseCode();
  
              if (responseCode == HttpsURLConnection.HTTP_OK) {
  
                  BufferedReader in = new BufferedReader(new
                          InputStreamReader(
                          conn.getInputStream()));
  
                  StringBuffer sb = new StringBuffer("");
                  String line = "";
  
                  while ((line = in.readLine()) != null) {
  
                      sb.append(line);
                      break;
                  }
  
                  in.close();
                  return sb.toString();
  
              } else {
                  return new String("false : " + responseCode);
              }
          } catch (Exception e) {
              return new String("Exception: " + e.getMessage());
          }
  
      }
  
      @Override
      protected void onPostExecute(String result) {
          Log.e("result", "" + result);
          try {
              JSONObject jo = new JSONObject(result);
              Log.e("ConstantClass.resJSon", "" + jo);
              JSONArray jsonArray = new JSONArray(jo.getString("Students"));
              for (int i = 0; i &lt; jsonArray.length(); i++) {
  
                  HashMap&lt;String, String&gt; reqedetails = new HashMap&lt;&gt;();
  
                  reqedetails.put("stu_no", jsonArray.getJSONObject(i).getString("AdmissionNo"));
                  reqedetails.put("stu_name", jsonArray.getJSONObject(i).getString("Name"));
                  String s1 = jsonArray.getJSONObject(i).getString("AdmissionNo");
                  Log.e("s1", "" + s1);
                  StudentDetailsList.add(reqedetails);
                  Log.e("StudentDetailsList.....", "" + StudentDetailsList);
              }
  
  
              rdrecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL,
                      false));
              rdrecyclerView.setItemAnimator(new DefaultItemAnimator());
              rdrecyclerView.setAdapter(new StudentDetailsAdapter(getApplicationContext(), StudentDetailsList));
          } catch (JSONException e) {
              e.printStackTrace();
  
  
          }
  
      }
  
      public String getPostDataString(JSONObject params) throws Exception {
  
          StringBuilder result = new StringBuilder();
          boolean first = true;
  
          Iterator&lt;String&gt; itr = params.keys();
  
          while (itr.hasNext()) {
  
              String key = itr.next();
              Object value = params.get(key);
  
              if (first)
                  first = false;
              else
                  result.append("&amp;");
  
              result.append(URLEncoder.encode(key, "UTF-8"));
              result.append("=");
              result.append(URLEncoder.encode(value.toString(), "UTF-8"));
  
          }
          return result.toString();
      }
  }
  public void getjsondata() {
      // Reading json file from assets folder
      StringBuffer sb = new StringBuffer();
      BufferedReader br = null;
      try {
          br = new BufferedReader(new InputStreamReader(getAssets().open(
                  "Student.json")));
          String temp;
          while ((temp = br.readLine()) != null)
              sb.append(temp);
      } catch (IOException e) {
          e.printStackTrace();
      } finally {
          //                br.close(); // stop reading
      }
      ConstantClass.myjsonstring = sb.toString();}}
  </code></pre>