Don't know how to finish the Firebase RecyclerAdapter

to don something
don meaning slang
don urban dictionary
don meaning italian
don synonym
don in a sentence
don in english
don medical abbreviation

I've been breaking my head trying to figure out how to get the Firebase RecyclerAdapter to work, but cannot get through this point. I read a lot of threads on Stack Overflow, but can't figure it out.

I haven't completed the onBindViewHolder yet but, the onCreateViewHolder is not working either. the word "parent" is always in red.

The problem is in the AllUserActivitys.java file and I have provided the rest of the code as well.

Here is my code:

AllUsersActivity.java:

package com.example.android.whammychat;

import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class AllUsersActivity extends AppCompatActivity {

    private Toolbar mAllUsersToolBar;
    private RecyclerView mAllUsersRecyclerView;
    private DatabaseReference mAllUsersDatabase;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_users);

        mAllUsersToolBar = findViewById(R.id.allUsersToolBar);
        setSupportActionBar(mAllUsersToolBar);
        getSupportActionBar().setTitle("All Users");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mAllUsersDatabase = FirebaseDatabase.getInstance().getReference().child("Users");

        mAllUsersRecyclerView = findViewById(R.id.allUsersRecyclerView);
        mAllUsersRecyclerView.setHasFixedSize(true);
        mAllUsersRecyclerView.setLayoutManager(new LinearLayoutManager(this));



    }

    //We are putting this in .onStart because we want to retrieve the data in real time.
    @Override
    protected void onStart() {
        super.onStart();


        FirebaseRecyclerOptions<Users> options =
                new FirebaseRecyclerOptions.Builder<Users>()
                        .setQuery(mAllUsersDatabase, Users.class)
                        .build();


        FirebaseRecyclerAdapter firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(options) {

            @NonNull
            @Override
            public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.individual_user, parent, false);

                return new UsersViewHolder(view);

            }

            @Override
            protected void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position, @NonNull Object model) {

            }

        };


    }


    public class UsersViewHolder extends RecyclerView.ViewHolder {

        View mView;

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

            /*
           itemView is a single row in the ListView.
           We are going to be using mView later to perform an onClickListener method on the ViewHolder.
             */
            mView = itemView;

        }
    }

}

Users.java:

package com.example.android.whammychat;

public class Users {

    public String username;
    public String status;
    public String image;

    //Constructor without parameters is also needed because: https://stackoverflow.com/questions/18993936/how-to-best-explain-and-use-empty-constructors-in-java
    public Users() {

    }

    public Users(String username, String status, String image) {
        this.username = username;
        this.status = status;
        this.image = image;
    }

    //Getters
    public String getUsername() {
        return username;
    }

    public String getStatus() {
        return status;
    }

    public String getImage() {
        return image;
    }


}

activity_all_users:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".AllUsersActivity">

    <include
        android:id="@+id/allUsersToolBar"
        layout="@layout/app_bar"/>

    <view
        android:id="@+id/allUsersRecyclerView"
        class="android.support.v7.app.AlertController$RecycleListView"
        android:layout_width="match_parent"
        android:layout_height="512dp"
        android:layout_marginTop="56dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </view>

</android.support.constraint.ConstraintLayout>

individual_user.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="139dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:id="@+id/individualUserPictureImageView"
            android:layout_width="105dp"
            android:layout_height="100dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="20dp"
            android:src="@drawable/profile_pic"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/individualUserStatusTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginStart="24dp"
            android:layout_marginTop="12dp"
            android:text="TextView"
            android:textSize="18sp"
            app:layout_constraintStart_toEndOf="@+id/individualUserPictureImageView"
            app:layout_constraintTop_toBottomOf="@+id/individualUserNameTextView" />

        <TextView
            android:id="@+id/individualUserNameTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/individualUserStatusTextView"
            android:layout_marginStart="24dp"
            android:layout_marginTop="28dp"
            android:text="TextView"
            android:textColor="@android:color/black"
            android:textSize="24sp"
            android:textStyle="bold"
            app:layout_constraintStart_toEndOf="@+id/individualUserPictureImageView"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>


</android.support.constraint.ConstraintLayout>

EDIT: The "RecyclerView.ViewHolder" in the AllUsersActivity.java file part is underlined in red now because it says that the FirebaseRecyclerAdapter is clashing with the android.support.v7.widget.RecyclerView.adapter. I tried deleting import android.support.v7.widget.RecyclerView; from the AllUsersActivity.java file but it keeps on automatically coming back. What can I do?

This code is working now. AllUsersActivity

public class AllUsersActivity extends AppCompatActivity {

    private Toolbar mAllUsersToolBar;
    private RecyclerView mAllUsersRecyclerView;
    FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseUsersAdapter = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_users);

        mAllUsersToolBar = findViewById(R.id.allUsersToolBar);
        setSupportActionBar(mAllUsersToolBar);
        getSupportActionBar().setTitle("All Users");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        mAllUsersRecyclerView = findViewById(R.id.allUsersRecyclerView);

        Query query = FirebaseDatabase.getInstance().getReference().child("Users"); // you can add child as .child("child_name");

        FirebaseRecyclerOptions<Users> options = new FirebaseRecyclerOptions.Builder<Users>()
                .setQuery(query, Users.class)
                .build();

         firebaseUsersAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(
                options) {
            @Override
            protected void onBindViewHolder(UsersViewHolder holder, int position, Users model) {
                holder.mIndividualUserName.setText(model.getUsername());
                holder.mIndividualUserStatus.setText(model.getStatus());
                holder.mIndividualUserPicture.setImageDrawable(getDrawable(R.drawable.profile_pic));
            }

            @Override
            public UsersViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.individual_user, parent, false);
                return new UsersViewHolder(view);
            }
        };

        mAllUsersRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAllUsersRecyclerView.setAdapter(firebaseUsersAdapter);
        firebaseUsersAdapter.startListening();

    }

    @Override
    protected void onResume() {
        super.onResume();
        if(firebaseUsersAdapter != null){
            firebaseUsersAdapter.startListening();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(firebaseUsersAdapter != null){
            firebaseUsersAdapter.stopListening();
        }
    }
}

UsersViewHolder I extracted this class out of the activity, this gonna help you to have a better code.

public class UsersViewHolder extends RecyclerView.ViewHolder {

    protected ImageView mIndividualUserPicture;
    protected TextView mIndividualUserName;
    protected TextView mIndividualUserStatus;


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

        mIndividualUserPicture = itemView.findViewById(R.id.individualUserPictureImageView);
        mIndividualUserName = itemView.findViewById(R.id.individualUserNameTextView);
        mIndividualUserStatus = itemView.findViewById(R.id.individualUserStatusTextView);


    }
}

Also i made a little change in the individual_user layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="139dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:id="@+id/individualUserPictureImageView"
            android:layout_width="105dp"
            android:layout_height="100dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="20dp"
            android:src="@drawable/profile_pic"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/individualUserStatusTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginStart="24dp"
            android:layout_marginTop="12dp"
            android:text="TextView"
            android:textSize="18sp"
            app:layout_constraintStart_toEndOf="@+id/individualUserPictureImageView"
            app:layout_constraintTop_toBottomOf="@+id/individualUserNameTextView" />

        <TextView
            android:id="@+id/individualUserNameTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@+id/individualUserStatusTextView"
            android:layout_marginStart="24dp"
            android:layout_marginTop="28dp"
            android:text="TextView"
            android:textColor="@android:color/black"
            android:textSize="24sp"
            android:textStyle="bold"
            app:layout_constraintStart_toEndOf="@+id/individualUserPictureImageView"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>


</android.support.constraint.ConstraintLayout>

I tested this code and the app run as expected.

App:

If you need something else, you can send me a message in my email address, you have it in your database ;)

Don, synonyms: university teacher, (university) lecturer, fellow, professor, reader, lector, college tutor, academic, scholar, egghead, senior common room Don (also dōn) Used as a courtesy title before the name of a man in a Spanish-speaking area. 2.

The problem is in your onCreateViewHolder

Replace:

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.individual_user, parent, false);

    return new UsersViewHolder(view);

}

With:

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(viewGroup.getContext())
            .inflate(R.layout.individual_user, viewGroup, false);
    return new UsersViewHolder(view);

}

Don, Don definition is - to put on (an article of clothing). How to use don in a sentence. Don definition, Mr.; Sir: a Spanish title prefixed to a man's given name.

To solve this, just change the following line of code:

View view = LayoutInflater.from(parent.getContext())
        .inflate(R.layout.individual_user, parent, false);

to

View view = LayoutInflater.from(viewGroup.getContext())
        .inflate(R.layout.individual_user, parent, false);

In your code, the partent view group is the viewGroup object that is coming as an argument in your onCreateViewHolder() method.

If you are interested, this is a recommended way in which you can retrieve data from a Firebase Realtime database and display it in a RecyclerView using FirebaseRecyclerAdapter.

Don, Don definition, Mr.; Sir: a Spanish title prefixed to a man's given name. See more. Don, and dom, is derived from the Latin Dominus : a master of a household, a title with background from the Roman Republic in classical antiquity.

don, DCP DeSilva (Boman Irani) sees a way to bring to justice the feared head of a criminal empire by recruiting a man named Vijay, who looks exactly like the crime boss (Shah Rukh Khan). The ruse works too well, and soon Vijay finds his life in danger Directed by Farhan Akhtar. With Shah Rukh Khan, Priyanka Chopra, Arjun Rampal, Isha Koppikar. Vijay is recruited by a police officer to masquerade as his lookalike Don, the leader of an international gang of smugglers.

Don, Head of any mafia crime family. 2. Dom Perignon. Expensive Champagne. Often called 'Don' in the suburbs and hood as a joke that we don't know what it is. 3. A don is a guy that everyone wants to be like. He is not only sexy and muscular but amazing in bed aswell. He can rock anyone. Being a don is a talent that not everyone can achieve.

don, A contraction of Middle English do on (“put on”), from Old English dōn on. Compare also doff, dup, dout. VerbEdit. don (third-person singular simple present dons,  Don Knotts 4-Movie Collection (The Apple Dumpling Gang / The Apple Dumpling Gang Rides Again / Gus / Hot Lead & Cold Feet) 4.7 out of 5 stars 640 DVD

Comments
  • instead of using parent use viewgorup man
  • Thank you very much! Could you read the EDIT i added in the original post please?
  • I edited my response, your firebaseRecyclerAdapter should use UsersViewHolder instead RecyclerView.ViewHolder. This should work.
  • Okay that worked! The onBindViewHolder code you suggested is not working. After .setText(Users.) the get(position) method cannot be applied. What can I do here?
  • There you need get the users that you are passing in the query. users is the parameter model in the onBindViewHolder, you can change the name model to users.
  • I edited the method onBindViewHolder
  • Awesome this seems to be working. The "RecyclerView.ViewHolder" part is underlined in red now because it says that the FirebaseRecyclerAdapter is clashing with the android.support.v7.widget.RecyclerView.adapter. I tried deleting import android.support.v7.widget.RecyclerView; from the AllUsersActivity.java file but it keeps on automatically coming back. What can I do?