title: How to display list array data from model class in recyclerview adapter according to their position?
body: <p>As below json response, i want to show <code>poolquestions</code> with answers related to that <code>poolquestion</code> in recyclerview. already i have defined a adapter for recyclerview and model class for <code>poolquestions</code> and answers to save json values. but my question is while i am going to extract data from model class in adapter all <code>poolanswers</code> are showing in all parent <code>poolquestions</code>.</p>
  
  <p>Here is my json:</p>
  
  <pre><code>{
    "data": [
      {
        "pooltitle": "Who is the best Actor in India",
        "pooldetails": [
          {
            "poolquestions": "Who is the best actor in Bollywood?",
            "poolanswer": [
              {
                "answer": "Amir Khan",
                "percent": 38
              },
              {
                "answer": "Amitabh Bachhan",
                "percent": 25
              },
              {
                "answer": "Salman Khan",
                "percent": 0
              },
              {
                "answer": "Akshay Kumar",
                "percent": 38
              }
            ]
          },
          {
            "poolquestions": "Who has most female fan following?",
            "poolanswer": [
              {
                "answer": "Amitabh Bachhan",
                "percent": 13
              },
              {
                "answer": "Amir Khan",
                "percent": 38
              },
              {
                "answer": "Salman Khan",
                "percent": 13
              },
              {
                "answer": "Akshay Kumar",
                "percent": 38
              }
            ]
          },
          {
            "poolquestions": "Who is most popular actor in social media?",
            "poolanswer": [
              {
                "answer": "Amir Khan",
                "percent": 27
              },
              {
                "answer": "Amitabh Bachhan",
                "percent": 36
              },
              {
                "answer": "Salman Khan",
                "percent": 18
              },
              {
                "answer": "Akshay Kumar",
                "percent": 18
              }
            ]
          }
        ]
      }
    ],
    "status": 1
  }
  </code></pre>
  
  <p>Main Activity AsyncTask code:</p>
  
  <pre><code>private List&lt;PollsData&gt; pollDataArrayList;
  private List&lt;PollQstWithOptions&gt; pollQSTOptionsList = new ArrayList&lt;&gt;();
  
  if ("1".equalsIgnoreCase(status)) {
              try {
                  JSONArray data = js.getJSONArray("data");
                  for (int i = 0; i &lt; data.length(); i++) {
                      JSONObject detailsData = data.getJSONObject(i);
  
                      JSONArray pollQstArray = detailsData.getJSONArray("pooldetails");
                      for (int j = 0; j &lt; pollQstArray.length(); j++) {
                          JSONObject poll = pollQstArray.getJSONObject(j);
                          String poolquestion_ = poll.getString("poolquestions");
                          pollDataArrayList = new ArrayList&lt;&gt;();
                          JSONArray poolanswerArray = poll.getJSONArray("poolanswer");
                          for (int k = 0; k &lt; poolanswerArray.length(); k++) {
                              JSONObject pollOptions = poolanswerArray.getJSONObject(k);
                              String options = pollOptions.getString("answer");
                              int percent = pollOptions.getInt("percent");
  
                              PollsData pollDetails = new PollsData(options, percent);
                              pollDataArrayList.add(pollDetails);
                          }
                          PollQstWithOptions mPollQstWithOptions = new PollQstWithOptions(poolquestion_, pollDataArrayList);
                          pollQSTOptionsList.add(mPollQstWithOptions);
                      }
  
                  }
              } catch (Exception e) {
                  e.printStackTrace();
              }
              mAdapter = new PollAdapter2(ActivityPollDetails.this, pollQSTOptionsList);
              RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(ActivityPollDetails.this);
              recyclerView.setLayoutManager(mLayoutManager);
              recyclerView.setHasFixedSize(true);
              recyclerView.setAdapter(mAdapter);
  
          }
  </code></pre>
  
  <p>Adapter class:</p>
  
  <pre><code>public class PollAdapter2 extends RecyclerView.Adapter&lt;PollAdapter2.MyViewHolder&gt; {
      private List&lt;PollQstWithOptions&gt; dataList;
      Context context;
  
      public class MyViewHolder extends RecyclerView.ViewHolder {
  
          TextView txt_poll_question;
  
          ProgressBar progress1;
          LinearLayout mainLayout;
          public MyViewHolder(View view) {
              super(view);
  
              txt_poll_question=(TextView)view.findViewById(R.id.txt_poll_question);
              mainLayout=(LinearLayout)view.findViewById(R.id.mainLayout);
          }
  
      }
      public PollAdapter2(Context mContext, List&lt;PollQstWithOptions&gt; dataList) {
          this.dataList = dataList;
          this.context=mContext;
      }
  
      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.card_poll_qst_with_ans, parent, false);
  
          MyViewHolder viewHolder = new MyViewHolder(v);
  
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder(final MyViewHolder holder, int position) {
          final PollQstWithOptions poll = dataList.get(position);
  
          holder.txt_poll_question.setText(poll.getPollQstName());
  
          for(int i=0; i&lt;dataList.size();i++){
              PollQstWithOptions itemsData = dataList.get(i);
              for(int j=0;j&lt;itemsData.getOptionList().size();j++){
                  System.out.print("child pos:: "+j);
                  PollsData mPollsData = itemsData.getOptionList().get(j);
  
                  TextView text = new TextView(context);
                  text.setLayoutParams(new TableRow.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                  text.setText(mPollsData.getAns1());
                  holder.mainLayout.addView(text);
              }
  
          }
  
      }
  
      @Override
      public int getItemCount() {
          return dataList.size();
      }
  
  
  }
  </code></pre>