Java – Why can’t I use the populateViewHolder override method?

Why can’t I use the populateViewHolder override method?… here is a solution to the problem.

Why can’t I use the populateViewHolder override method?

I

tried retrieving data from the database in the fragment onViewCreated method, and I used the FirebaseRecylerAdapter shown below

@Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

FirebaseRecyclerAdapter<AllUsers, AllUsersViewHolder> firebaseRecyclerAdapter;
    }

public static class AllUsersViewHolder extends RecyclerView.ViewHolder {

View view;

public AllUsersViewHolder(View itemView) {
            super(itemView);
            view = itemView;
        }
    }

When I use firebaseRecyclerAdapter = new FirebaseRecyclerAdapter, it doesn’t give me the populateViewHolder method, it only provides the following method

FirebaseRecyclerAdapter<AllUsers, AllUsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<AllUsers, AllUsersViewHolder>() {
            @Override
            protected void onBindViewHolder(AllUsersViewHolder holder, int position, AllUsers model) {

}

@Override
            public AllUsersViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                return null;
            }
        };

Can anyone tell me why this is so

Solution

Firebase... The constructor of the Adapter class has changed in FirebaseUI version 3. Given this query:

Query query = FirebaseDatabase.getInstance()
    .getReference()
    .child("users")
    .equalTo(name);

If you are using version 3 or later, use FirebaseRecyclerOptions:

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

Then declare a FirebaseRecyclerAdapter:

FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Chat, ChatHolder>(options) {

Add the variable options as described above. It is a variable of the FirebaseRecyclerOptions

class

Then to add an item, you must use onBindViewHolder, as it is the latest version of Firebase UI:

 @Override
protected void onBindViewHolder(Holder holder, int position, model_class_name model) {
     Bind the class object to the holder
    // ...
}

For more information, check out: https://github.com/firebase/FirebaseUI-Android/tree/master/database

Related Problems and Solutions