Retrieving data from firebase to recyclerview does not work

by Martynas   Last Updated October 09, 2019 14:26 PM

As mentioned in the title, my recyclerview does not work. No idea why, because I do not get any errors or anything in the logcat or while building the app. Is there a way I could debug this or could you point out the mistake that I did?

I've implemented another recyclerview with the adapter, but I used a simple adapter. I tried using the firebaseUI in this case, and it seems that the adapter somehow cannot retrieve the data from the firebase firestore

My adapter:

public class ManageAdapter extends FirestoreRecyclerAdapter<Manage, ManageAdapter.ManageHolder> {

    public ManageAdapter(@NonNull FirestoreRecyclerOptions<Manage> options) {
        super(options);
    }

    @Override
    protected void onBindViewHolder(@NonNull ManageHolder holder, int position, @NonNull Manage model) {
        holder.textviewName.setText(model.getName());
        holder.textviewGrade.setText(model.getGrade());
        //holder.textviewAge.setText(String.valueOf(model.getAge()));

    }

    @NonNull
    @Override
    public ManageHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v  = LayoutInflater.from(parent.getContext()).inflate(R.layout.manage_item,
        parent,false);

        return new ManageHolder(v);
    }

    class ManageHolder extends RecyclerView.ViewHolder{
        TextView textviewName;
        TextView textviewAge;
        TextView textviewGrade;

        public ManageHolder(@NonNull View itemView) {
            super(itemView);
            textviewAge = itemView.findViewById(R.id.manage_item_title_age);
            textviewGrade = itemView.findViewById(R.id.manage_item_grade);
            textviewName = itemView.findViewById(R.id.manage_item_name);
        }
    }
}

Main class:


    private FirebaseFirestore firebaseFirestore;
    private Toolbar mToolbar;
    private Button delete_event;
    private RecyclerView participants;
    private TextView manage_events_title;
    private TextView participans_text;
    private ManageAdapter adapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manage_events);
        final String ID = getIntent().getExtras().getString("ID");
        firebaseFirestore = FirebaseFirestore.getInstance();

        delete_event = (Button) findViewById(R.id.delete_event);
        manage_events_title = (TextView) findViewById(R.id.manage_events_title);
        participans_text = (TextView) findViewById(R.id.participants_text);
        participants = (RecyclerView) findViewById(R.id.recyclerview_manage);

        setUpRecyclerView();
    }

    private void setUpRecyclerView(){
        final String ID = getIntent().getExtras().getString("ID");
        Query query = firebaseFirestore.collection("Events").document(ID).collection("Users");
        FirestoreRecyclerOptions<Manage> options = new FirestoreRecyclerOptions.Builder<Manage>()
                .setQuery(query, Manage.class).build();
        adapter = new ManageAdapter(options);
        participants.setHasFixedSize(true);
        participants.setLayoutManager(new LinearLayoutManager(this));
        participants.setAdapter(adapter);
    }

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

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



Related Questions


Updated September 02, 2018 08:26 AM

Updated July 03, 2018 13:26 PM

Updated November 09, 2018 03:26 AM

Updated May 03, 2018 21:26 PM