Why I cant use the populateViewHolder override method?
I'm try to retrieve datafrom database
in my fragment
onViewCreated
method I have used FirebaseRecylerAdapter like 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 wont give me the populateViewHolder
method just give method like below
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 someone please tell me why this is happening
Solution 1:
The constructor of the Firebase...Adapter
classes has changed in FirebaseUI version 3. Given this query:
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("users")
.equalTo(name);
If you're using a version 3 or higher, you 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 above. It is the variable of the class FirebaseRecyclerOptions
Then to add items you have to use onBindViewHolder
since its 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 info check this: https://github.com/firebase/FirebaseUI-Android/tree/master/database