title: Implements OnClickListener in cardview to get specific data
body: <p><a href="https://i.stack.imgur.com/FAkhr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FAkhr.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/lGsam.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lGsam.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/RnhDq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RnhDq.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/WO9dj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WO9dj.png" alt="enter image description here" /></a></p>
  <p>With the code I have currently, I get to retrieve every attendance details [image 3] when Onclick on any cardview[image 2].</p>
  <p>Now, I hope to get the specific data in each cardview.</p>
  <p>Flow: <strong>userlist.java</strong> [implements OnClickListener here]-&gt; <strong>userlist1.java</strong></p>
  <p>Hoping results:</p>
  <p>CardView 1 [info:test3] -&gt;  1 Attendance  (MdkeONsLFaBK9DgyKMu)</p>
  <p>CardView 2 [info:rea] -&gt; 2 Attendance  (Mdkf_TBTWI4D6yRyGLa) &amp; (Mdkfbbtb2mRUZXEIwdr)</p>
  <p><strong>userlist.class</strong></p>
  <pre><code>public class userlist extends AppCompatActivity {
  
      RecyclerView recyclerView;
      DatabaseReference database, ab;
      MyAdapter myAdapter;
      ArrayList&lt;Report&gt; list;
      String uid;
      private FirebaseAuth auth;
      private FirebaseUser user;
      Menu menu;
      private SearchView searchView = null;
      private SearchView.OnQueryTextListener queryTextListener;
      SharedPreferences sharedpreferences;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_userlist);
  
          user = auth.getInstance().getCurrentUser();
          uid = user.getUid();
  
          recyclerView = findViewById(R.id.userlist);
          searchView = findViewById(R.id.action_search);
  
          SharedPreferences sharedPreferences = getSharedPreferences(&quot;myKey&quot;, MODE_PRIVATE);
          String key = sharedPreferences.getString(&quot;key&quot;,&quot;&quot;);
          String temp = sharedPreferences.getString(&quot;temp&quot;,&quot;&quot;);
  
  
          database = FirebaseDatabase.getInstance().getReference(&quot;Class Information&quot;);
          ab = database.child(uid).child(&quot;Student Attend&quot;);
  
          recyclerView.setHasFixedSize(true);
          recyclerView.setLayoutManager(new LinearLayoutManager(this));
  
          list = new ArrayList&lt;&gt;();
          myAdapter = new MyAdapter(this, list);
          recyclerView.setAdapter(myAdapter);
  
          ab.addValueEventListener(new ValueEventListener() {
  
              @Override
              public void onDataChange(@NonNull DataSnapshot snapshot) {
                  for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
  
                      Report report = dataSnapshot.getValue(Report.class);
                      list.add(report);
  
                  }
                  myAdapter.notifyDataSetChanged();
  
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError databaseError) {
  
              }
          });
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.menu, menu);
  
          // Associate searchable configuration with the SearchView
          SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
          searchView = (SearchView) menu.findItem(R.id.action_search)
                  .getActionView();
          searchView.setSearchableInfo(searchManager
                  .getSearchableInfo(getComponentName()));
          searchView.setMaxWidth(Integer.MAX_VALUE);
  
          // listening to search query text change
          searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
              @Override
              public boolean onQueryTextSubmit(String query) {
                  // filter recycler view when query submitted
                  myAdapter.getFilter().filter(query);
                  return false;
              }
  
              @Override
              public boolean onQueryTextChange(String query) {
                  // filter recycler view when text is changed
                  myAdapter.getFilter().filter(query);
                  return false;
              }
          });
          return true;
      }
  
  
      @Override
      public boolean onOptionsItemSelected(@NonNull MenuItem item) {
          switch (item.getItemId()) {
              case R.id.menu_dateascending:
                  Collections.sort(list, Report.ReportDateOldestComparator);
                  Toast.makeText(userlist.this, &quot;Sort by Date [Oldest - Latest]&quot;, Toast.LENGTH_SHORT).show();
                  myAdapter.notifyDataSetChanged();
                  return true;
  
              case R.id.menu_descending:
                  Collections.sort(list, Report.ReportDateLatestComparator);
                  Toast.makeText(userlist.this, &quot;Sort by Date [Latest - Oldest]&quot;, Toast.LENGTH_SHORT).show();
                  myAdapter.notifyDataSetChanged();
                  return true;
              case R.id.action_search:
                  // Not implemented here
                  return false;
              default:
                  break;
          }
          searchView.setOnQueryTextListener(queryTextListener);
          return super.onOptionsItemSelected(item);
      }
  }
  
  </code></pre>
  <p><strong>MyAdapter.java</strong></p>
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.MyViewHolder&gt;implements Filterable {
  
  
      Context context;
      ArrayList&lt;Report&gt; list;
      ArrayList&lt;Report&gt; listfilter;
      SharedPreferences sharedpreferences;
  
  
      public MyAdapter(Context context, ArrayList&lt;Report&gt; list) {
          this.context = context;
          this.list = list;
          this.listfilter = list;
  
      }
  
  
      @NonNull
      @Override
      public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(context).inflate(R.layout.item,parent,false);
          return new MyViewHolder(v);
  
  
      }
  
      @Override
      public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
  
          Report report = list.get(position);
          holder.time.setText(report.getTime());
          holder.duration.setText(report.getDuration());
          holder.info.setText(report.getInfo());
  
      }
  
      @Override
      public int getItemCount() {
          return list.size();
      }
  
      @Override
      public Filter getFilter() {
          return new Filter() {
              @Override
              protected FilterResults performFiltering(CharSequence charSequence) {
                  String charString = charSequence.toString();
                  if (charString.isEmpty()) {
                      list = listfilter;
                  } else {
                      List&lt;Report&gt; filteredList = new ArrayList&lt;&gt;();
                      for (Report row : listfilter) {
  
                          // name match condition. this might differ depending on your requirement
                          // here we are looking for name or phone number match
                          if (row.getInfo().toLowerCase().contains(charString.toLowerCase()) || row.getTime().contains(charSequence)) {
                              filteredList.add(row);
                          }
                      }
                      list = (ArrayList&lt;Report&gt;) filteredList;
                  }
  
                  FilterResults filterResults = new FilterResults();
                  filterResults.values = list;
                  return filterResults;
              }
  
              @Override
              protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
                  list = (ArrayList&lt;Report&gt;) filterResults.values;
                  notifyDataSetChanged();
              }
          };
      }
  
  
      public class MyViewHolder extends RecyclerView.ViewHolder { 
  
          TextView duration, time, info;
          public View view;
          String key, temp;
  
          public MyViewHolder(@NonNull View itemView) {
              super(itemView);
  
              time = itemView.findViewById(R.id.tvtemp);
              duration = itemView.findViewById(R.id.tvfirstName);
              info = itemView.findViewById(R.id.tvmatno);
  
              SharedPreferences sharedPreferences = context.getSharedPreferences(&quot;myKey&quot;, Context.MODE_PRIVATE);
              String key = sharedPreferences.getString(&quot;key&quot;,&quot;&quot;);
              String temp = sharedPreferences.getString(&quot;temp&quot;,&quot;&quot;);
  
              itemView.setOnClickListener(new View.OnClickListener() {
  
                  @Override
                  public void onClick(View itemView) {
  
                      sharedpreferences = context.getSharedPreferences(&quot;myKey&quot;, Context.MODE_PRIVATE);
                      SharedPreferences.Editor editor = sharedpreferences.edit();
                      editor.putString(&quot;key&quot;, key);
                      editor.putString(&quot;temp&quot;, temp);
                      editor.apply();
  
                      Intent intent = new Intent(itemView.getContext(), userlist1.class);
                      itemView.getContext().startActivity(intent);// pass key to next activity;
  
                      Toast.makeText(itemView.getContext(), &quot;Data retrieved from database&quot;, Toast.LENGTH_SHORT).show();
  
                  }
              });
          }
      }
  }
  </code></pre>
  <p><strong>Report.java</strong></p>
  <pre><code>public class Report {
  
      public String duration;
      public String time;
      public String info;
  
      public Report(){
  
      }
  
      public void setDuration(String duration) {
          this.duration = duration;
      }
  
      public void setTime(String time) {
          this.time = time;
      }
  
      public void setInfo(String info) {
          this.info = info;
      }
  
  
      public String getDuration() {
          return duration;
      }
  
      public String getTime() {
          return time;
      }
  
      public String getInfo() {
          return info;
      }
  
      public static Comparator&lt;Report&gt; ReportDateOldestComparator = new Comparator&lt;Report&gt;() {
          @Override
  
          public int compare(Report o1, Report o2) {
              return o1.getTime().compareTo(o2.getTime());
  
          }
      };
  
      public static Comparator&lt;Report&gt; ReportDateLatestComparator = new Comparator&lt;Report&gt;() {
          @Override
  
          public int compare(Report o1, Report o2) {
              return o2.getTime().compareTo(o1.getTime());
  
          }
      };
  }
  </code></pre>
  <p><strong>userlist1.java</strong></p>
  <pre><code>public class userlist1 extends AppCompatActivity {
  
      RecyclerView recyclerView;
      DatabaseReference database,ab;
      MyAdapter1 myAdapter1;
      ArrayList&lt;Report1&gt; list;
      String uid;
      private FirebaseAuth auth;
      private FirebaseUser user;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_userlist1);
  
          user = auth.getInstance().getCurrentUser();
          uid = user.getUid();
  
          recyclerView = findViewById(R.id.userlist1);
  
  
          SharedPreferences sharedPreferences = getSharedPreferences(&quot;myKey&quot;, MODE_PRIVATE);
          String key = sharedPreferences.getString(&quot;key&quot;,&quot;&quot;);
          String temp = sharedPreferences.getString(&quot;temp&quot;,&quot;&quot;);
          String abc = sharedPreferences.getString(&quot;abc&quot;,&quot;&quot;);
  
  
          database = FirebaseDatabase.getInstance().getReference(&quot;Class Information&quot;);
          ab = database.child(uid).child(&quot;Student Attend&quot;);
          //ab = database.child(uid).child(&quot;Student Attend&quot;).child(key).child(&quot;Attendance&quot;);
          //ab = database.child(uid).child(&quot;Student Attend&quot;).child(&quot;test&quot;).child(key);
          recyclerView.setHasFixedSize(true);
          recyclerView.setLayoutManager(new LinearLayoutManager(this));
  
          list = new ArrayList&lt;&gt;();
  
          //ArrayList&lt;Report1&gt; list = new ArrayList&lt;Report1&gt;();
          myAdapter1 = new MyAdapter1(this,list);
          recyclerView.setAdapter(myAdapter1);
  
  
          ab.addListenerForSingleValueEvent(new ValueEventListener() {
  
              @Override
              public void onDataChange(@NonNull DataSnapshot snapshot) {
                  for (DataSnapshot childSnapshot : snapshot.getChildren()) {
  
                      /*List&lt;Report1&gt;list = new ArrayList&lt;&gt;();*/
                      for (DataSnapshot dataSnapshot : childSnapshot.child(&quot;Attendance&quot;).getChildren()) {
  
  
                          Report1 report1 = dataSnapshot.getValue(Report1.class);
                          list.add(report1);
                      }
                  }
             myAdapter1.notifyDataSetChanged();
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError databaseError) {
                  throw databaseError.toException(); // 
  
              }
          });
      }
  }
  </code></pre>
  <p><strong>MyAdapter1.java</strong></p>
  <pre><code>public class MyAdapter1 extends RecyclerView.Adapter&lt;MyAdapter1.MyViewHolder&gt; {
  
      Context context;
      ArrayList&lt;Report1&gt; list;
  
      public MyAdapter1(Context context, ArrayList&lt;Report1&gt; list) {
          this.context = context;
          this.list = list;
      }
  
  
      @NonNull
      @Override
      public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(context).inflate(R.layout.item1,parent,false);
          return new MyViewHolder(v);
      }
  
      @Override
      public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
  
          Report1 report1 = list.get(position);
          holder.matricno.setText(report1.getMatricno());
          holder.password.setText(report1.getPassword());
          holder.temp.setText(report1.getTemp());
      }
  
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public int getItemViewType(int position) {
          return position;
      }
  
      @Override
      public int getItemCount() {
  
          return list.size();
      }
  
      public class MyViewHolder extends RecyclerView.ViewHolder{ //public static class
  
          TextView matricno, password, temp;
          public View view;
  
          public MyViewHolder(@NonNull View itemView){
              super(itemView);
  
              matricno = itemView.findViewById(R.id.tvmno);
              password = itemView.findViewById(R.id.tvpassword);
              temp = itemView.findViewById(R.id.tvtemperature);
  
  
              itemView.setOnClickListener(new View.OnClickListener() {
  
                  @Override
                  public void onClick(View itemView) {
  
                      Toast.makeText(itemView.getContext(), &quot;Data retrieved from database&quot;, Toast.LENGTH_SHORT).show();
  
                  }
              });
          }
      }
  }
  </code></pre>
  <p><strong>Report1.java</strong></p>
  <pre><code>public class Report1 {
      public String matricno;
      public String password;
      public String temp;
  
  public Report1(){
  }
  
      public String getMatricno() {
          return matricno;
      }
  
      public String getPassword() {
          return password;
      }
  
      public String getTemp() {
          return temp;
      }
      public void setMatricno(String matricno) {
          this.matricno = matricno;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public void setTemp(String temp) {
          this.temp = temp;
      }
  
  }
  </code></pre>