title: How to show content from different ArrayLists in Recyclerview based on specific percentage?
body: <p>I have this simple recyclerview which shows content from an ArrayList. I want to show content from multiple ArrayLists based on the percentage. To put it simply: I want to put 2 ArrayLists in my code with different content. I want the Recyclerview to show content from both the arrayLists but not entirely. I want to set specific percentage for both the ArrayLists. Say, if I want to show 30% content from the ArrayList1 (with 10 items) and 70% content from ArrayList2 (with 10 items) then my recyclerview shoud show 3 items from ArrayList1 and 7 items from ArrayList2. (preferably in a random order).</p>
  <p>MainActivity.java:</p>
  <pre><code>    private void initView() {
      // Initialize RecyclerView and set Adapter
      recyclerView = findViewById(R.id.scout_recycler_view);
      recyclerView.setLayoutManager(new LinearLayoutManager(this));
      scoutArrayList = new ArrayList&lt;&gt;();
      adapter = new ScoutAdapter(this,scoutArrayList);
      recyclerView.setAdapter(adapter);
      createList();
  }
  
  private void createList() {
      //data to be shown in list
      scoutArrayList.add(new Scout( &quot;Eren Jaeger&quot; ,&quot;Unranked&quot; , &quot;22&quot; ));
      scoutArrayList.add(new Scout ( &quot;Mikasa Ackermann&quot; ,&quot;Unranked&quot; , &quot;12&quot; ) );
      scoutArrayList.add(new Scout ( &quot;Armin Arlelt&quot; ,&quot;Unranked&quot; , &quot;0&quot; ) );
      scoutArrayList.add(new Scout ( &quot;Erwin Smith &quot; , &quot;Commander&quot; , &quot;Unknown&quot; ) );
      scoutArrayList.add(new Scout ( &quot;Levi Ackermann&quot; , &quot;Squad Captain&quot; ,&quot;~58&quot; ) );
      scoutArrayList.add(new Scout ( &quot;Hange Zoe&quot; , &quot;Commander&quot; , &quot;Unknown&quot;) );
      scoutArrayList.add(new Scout ( &quot;Jean Kirschtein&quot; , &quot;Unranked&quot; , &quot;1&quot; )   );
      scoutArrayList.add(new Scout (&quot;Conny Springer&quot;, &quot;Unranked&quot; , &quot;Unknown&quot;) );
      scoutArrayList.add(new Scout (&quot;Sasha Braus&quot;,&quot;Unranked&quot;,&quot;1&quot;) );
  
  }
  
  private void createList2() {
      //data to be shown in list
      scoutArrayList2.add(new Scout( &quot;Testname2&quot; ,&quot;rankvalue2&quot; , &quot;killscount2&quot; ));
      scoutArrayList2.add(new Scout( &quot;Testname2&quot; ,&quot;rankvalue2&quot; , &quot;killscount2&quot; ));
      scoutArrayList2.add(new Scout( &quot;Testname2&quot; ,&quot;rankvalue2&quot; , &quot;killscount2&quot; ));
      scoutArrayList2.add(new Scout( &quot;Testname2&quot; ,&quot;rankvalue2&quot; , &quot;killscount2&quot; ));
      scoutArrayList2.add(new Scout( &quot;Testname2&quot; ,&quot;rankvalue2&quot; , &quot;killscount2&quot; ));
      scoutArrayList2.add(new Scout( &quot;Testname2&quot; ,&quot;rankvalue2&quot; , &quot;killscount2&quot; ));
      scoutArrayList2.add(new Scout( &quot;Testname2&quot; ,&quot;rankvalue2&quot; , &quot;killscount2&quot; ));
      scoutArrayList2.add(new Scout( &quot;Testname2&quot; ,&quot;rankvalue2&quot; , &quot;killscount2&quot; ));
      scoutArrayList2.add(new Scout( &quot;Testname2&quot; ,&quot;rankvalue2&quot; , &quot;killscount2&quot; ));
  }
  </code></pre>
  <p>Adapter.java</p>
  <pre><code>   public ScoutAdapter(Context context, ArrayList&lt;Scout&gt; scouts) {
      this.context = context;
      this.scouts = scouts;
  
  }
  
  @NonNull
  @Override
  public ScoutHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(context).inflate(R.layout.item_row,parent,false);
      return new ScoutHolder(view);
  }
  
  @Override
  public void onBindViewHolder(@NonNull ScoutHolder holder, int position) {
      Scout scout = scouts.get(position);
      holder.setDetails(scout);
  }
  
  @Override
  public int getItemCount() {
      return scouts.size();
  }
  
  public class ScoutHolder extends RecyclerView.ViewHolder {
      private TextView txtName, txtRank, txtKill;
      public ScoutHolder(@NonNull View itemView) {
          super(itemView);
          txtName = itemView.findViewById(R.id.txtName);
          txtRank = itemView.findViewById(R.id.txtRank);
          txtKill = itemView.findViewById(R.id.txtKill);
      }
  
      public void setDetails(Scout scout) {
          txtName.setText(scout.getName());
          txtRank.setText(String.format(&quot;Rank: %s&quot;, scout.getRank()));
          txtKill.setText(String.format(&quot;kill: %s&quot;, scout.getKillCount()));
      }
  }
  </code></pre>
  <p>In the above code (MainActivity.java) there is this list named createList2(), I want to show 20% of the content from it......</p>
  <p>Any solution to this?</p>