title: How to get data from Firebase and display it in a recyclerview?
body: <p>I develop a chat app. I try to get data from firebase database and display it in a recyclerview, but it doesn't work. I searched it on Google and I tried a lot of options, but it displays nothing. What am I doing wrong?
  These are the activities:</p>
  
  <p>1.Main Activity(Where I want to display the data)</p>
  
  <pre><code>public class SearchActivity extends AppCompatActivity {
  Toolbar sToolbar;
  SearchView searchView;
  RecyclerView recyclerView;
  BottomNavigationView sBnv;
  SearchAdapter searchAdapter;
  LinearLayoutManager llm;
  ArrayList&lt;String&gt; arrayList;
  User user;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_search);
  
      sToolbar = findViewById(R.id.sToolbar);
      recyclerView = findViewById(R.id.sRecyclerView);
      sBnv = findViewById(R.id.sBnv);
  
      searchAdapter = new SearchAdapter(arrayList, getApplicationContext());
      recyclerView.setHasFixedSize(true);
      llm = new LinearLayoutManager(getApplicationContext());
  
      final DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("users");
  
      ref.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              if (dataSnapshot.exists()) {
                  for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                      String username = (String)
                              snapshot.child("username").getValue();
                      arrayList.add(username);
  
                  }
                  recyclerView.setLayoutManager(llm);
                  recyclerView.setAdapter(searchAdapter);
              }
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
          Toast.makeText(SearchActivity.this, "Database error", Toast.LENGTH_SHORT)
                  .show();
          }
      });
  </code></pre>
  
  <p>2.Adapter class: </p>
  
  <pre><code>public class SearchAdapter extends RecyclerView.Adapter&lt;SearchAdapter.ViewHolder&gt; {
  
  ArrayList&lt;String&gt; friendsSearchedList = new ArrayList&lt;&gt;();
  Context mContext;
  
  public SearchAdapter(ArrayList&lt;String&gt; friendsSearchedList, Context mContext){
      this.friendsSearchedList = friendsSearchedList;
      this.mContext = mContext;
  }
  
  @NonNull
  @Override
  public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.search_user_item,parent, false);
  ViewHolder holder = new ViewHolder(view);
  return holder;
  }
  
  @Override
  public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
      final String username = friendsSearchedList.get(position);
      holder.text.setText(username);
  
  }
  
  @Override
  public int getItemCount() {
  return friendsSearchedList == null ? 0:friendsSearchedList.size();
  }
  
  public class ViewHolder extends RecyclerView.ViewHolder {
  TextView text, text1, text2;
  Button button;
  RelativeLayout relativeLayout;
  public ViewHolder(View itemView){
  super(itemView);
  
  text = itemView.findViewById(R.id.sText);
  button = itemView.findViewById(R.id.addFriend);
  text1 = itemView.findViewById(R.id.sText1);
  text2 = itemView.findViewById(R.id.sText2);
  relativeLayout = itemView.findViewById(R.id.relativeLayout);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>3.User class:</p>
  
  <pre><code>public class User {
  public String  email, id, password;
  public String username;
  
  public User(String email, String username, String password){
  this.email = email;
  this.username = username;
  this.password = password;
  }
  public User(){}
  public void setUsername(String username){
  this.username = username;
  }
  public String getUsername(){
  return username;
  }
  public void setEmail(String email){
  this.email = email;
  }
  public String getEmail(){
  return email;
  }
  public String getPassword(){
  return password;
  }
  public void setPassword(String password){
  this.password = password;
  }
  </code></pre>
  
  <p>}</p>