I'm trying to retrieve from RealTime-Database the list of users with their First name and second name but nothing appears.
The class UsersActivity show all the users from the database.I tried a lot of tutorials but nothing seems to work.
public class UsersActivity extends AppCompatActivity {
private RecyclerView userslist;
private DatabaseReference ref;
private List<Users> mUsers;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate ( savedInstanceState );
setContentView ( R.layout.activity_users );
ref = FirebaseDatabase.getInstance ().getReference ().child ( "FirstName" );
userslist = (RecyclerView) findViewById ( R.id.users_list );
userslist.setHasFixedSize ( true );
userslist.setLayoutManager ( new LinearLayoutManager ( this ) );
}
public void readUsers(){
FirebaseUser firebaseUser= FirebaseAuth.getInstance ().getCurrentUser ();
DatabaseReference reference=FirebaseDatabase.getInstance ().getReference ("spors-budy-en866");
reference.addValueEventListener ( new ValueEventListener () {
@Override
public void onDataChange (@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onCancelled (@NonNull DatabaseError databaseError) {
}
} )
}
@Override
protected void onStart () {
super.onStart ();
FirebaseRecyclerOptions<Users> options = new FirebaseRecyclerOptions.Builder<Users> ()
.setQuery ( ref, Users.class )
.build ();
FirebaseRecyclerAdapter<Users, FindFriendViewHolder> adapter = new FirebaseRecyclerAdapter<Users, FindFriendViewHolder> ( options ) {
@Override
protected void onBindViewHolder (@NonNull FindFriendViewHolder findFriendViewHolder, int i, @NonNull Users users) {
findFriendViewHolder.userName.setText ( users.getName () );
}
@NonNull
@Override
public FindFriendViewHolder onCreateViewHolder (@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from ( parent.getContext () ).inflate ( R.layout.users_template, parent, false );
FindFriendViewHolder viewHolder = new FindFriendViewHolder ( view );
return viewHolder;
}
};
userslist.setAdapter ( adapter );
adapter.startListening ();
}
public static class FindFriendViewHolder extends RecyclerView.ViewHolder {
TextView userName;
ImageView profileImage;
public FindFriendViewHolder (@NonNull View itemView) {
super ( itemView );
userName = itemView.findViewById ( R.id.username1 );
profileImage = itemView.findViewById ( R.id.profilepicture );
}
}
}
The rules of my database:
{
"rules": {
".read": "true",
".write":"true",
"users":{
"$user_id":{
".read": "auth.uid === $user_id",
".write": "auth.uid === $user_id"
}
}
}
}
I expect to show all the users from my databse.But the activity is empty.