0

I'm having trouble with making my RecyclerView work. I have found previous solution to this problem where you have to comment or remove recyclerView.setHasFixedSize(true);. I have tried this and while it did made the application run successfully, all that came out was this:

this.

Here's my fragment code:

public class Leaderboard extends Fragment {

RecyclerView leaderboardList;
FirebaseFirestore fStore;
FirestoreRecyclerAdapter adapter;

public Leaderboard() {
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    fStore = FirebaseFirestore.getInstance();

    //Query
    Query query = fStore.collection("users")
            .orderBy("Score", Query.Direction.DESCENDING);

    //RecyclerOptions
    FirestoreRecyclerOptions<UserModel> options = new FirestoreRecyclerOptions.Builder<UserModel>()
            .setQuery(query, UserModel.class)
            .build();

     adapter = new FirestoreRecyclerAdapter<UserModel, UserViewHolder>(options) {
        @NonNull
        @Override
        public UserViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_leaderboard_single, parent, false);
            return new UserViewHolder(view);
        }

        @Override
        protected void onBindViewHolder(@NonNull UserViewHolder holder, int position, @NonNull UserModel model) {
            holder.username1.setText(model.getUsername());
            holder.email1.setText(model.getEmail());
            holder.score1.setText(model.getScore() + "");
        }
    };

    }
    
@Override
public void onStop() {
    super.onStop();
    adapter.stopListening();
}

@Override
public void onStart() {
    super.onStart();
    adapter.startListening();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_leaderboard, container, false);
    leaderboardList = view.findViewById(R.id.leaderboard_list);
    //leaderboardList.setHasFixedSize(true);
    leaderboardList.setLayoutManager(new LinearLayoutManager(getContext()));
    leaderboardList.setAdapter(adapter);

    return view;
}

private class UserViewHolder extends RecyclerView.ViewHolder {

    private TextView username1;
    private TextView email1;
    private TextView score1;

    public UserViewHolder(@NonNull View itemView) {
        super(itemView);

        username1 = itemView.findViewById(R.id.list_username);
        email1 = itemView.findViewById(R.id.list_email);
        score1 = itemView.findViewById(R.id.list_score);
    }
}

}

The model class:

public class UserModel {

private String username;
private String email;
private long score;

private UserModel(){

}

private UserModel(String username, String email, long score){
    this.username = username;
    this.email = email;
    this.score = score;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public long getScore() {
    return score;
}

public void setScore(long score) {
    this.score = score;
}

}

I am pretty much at a dead end here, I really really appreciate any help I can get. Thank you!

edit 1:

list_leaderboard_single.xaml code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="20dp">

<TextView
    android:id="@+id/list_username"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Username"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/list_email"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Email"
    app:layout_constraintStart_toStartOf="parent"

    app:layout_constraintTop_toBottomOf="@id/list_username"/>

<TextView
    android:id="@+id/list_score"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Score"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/list_email"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Scrin
  • 37
  • 7
  • 1
    seems more like a layout issue to me. What's the height of `R.layout.list_leaderboard_single`? It shouldn't be `match_parent` (cause it fills whole screen) – Stachu Dec 22 '20 at 17:49
  • @Stachu i added it on the post for my `R.layout.list_leaderboard_single` code segment and my heights are on `wrap_content` – Scrin Dec 22 '20 at 17:54
  • Not sure but maybe [this](https://stackoverflow.com/questions/49277797/how-to-display-data-from-firestore-in-a-recyclerview-with-android) link can help you on your issue. – Samuel Romero Dec 24 '20 at 19:41

0 Answers0