问题描述
@Override
public void onStart() {
super.onStart();
FirebaseRecyclerAdapter<AllUsers, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<AllUsers, UsersViewHolder>() {
@NonNull
@Override
public UsersViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null;
}
@Override
protected void onBindViewHolder(@NonNull UsersViewHolder holder, int position, @NonNull AllUsers model) {
holder.setName(model.getName());
holder.setStatus(model.getStatus());
}
};
mUsersList.setAdapter(firebaseRecyclerAdapter);
}
public static class UsersViewHolder extends RecyclerView.ViewHolder{
View mView;
public UsersViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setName(String name) {
TextView mDisplayName = (TextView) mView.findViewById(R.id.display_name);
mDisplayName.setText(name);
}
public void setStatus(String status) {
TextView mDisplayStatus = (TextView) mView.findViewById(R.id.display_status);
mDisplayStatus.setText(status);
}
}
错误在以下行中,在()
下有一条红线显示: FirebaseRecyclerAdapter<AllUsers, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<AllUsers, UsersViewHolder>() {
The error is in the following line in which theres a red line showing under ()
: FirebaseRecyclerAdapter<AllUsers, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<AllUsers, UsersViewHolder>() {
其中的参数应该是什么?
What should be the parameters that come inside that?
推荐答案
您需要执行以下操作:
DatabaseReference ref=FirebaseDatabase.getInstance().getReference();
Query query=ref.child("Users").orderByChild("name").equalTo(name);
FirebaseRecyclerOptions<AllUsers> options =
new FirebaseRecyclerOptions.Builder<AllUsers>()
.setQuery(query, AllUsers.class)
.build();
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<AllUsers, UsersViewHolder>(options) {
首先,您需要通过构建FirebaseRecyclerOptions
First, you need to configure the adapter by building FirebaseRecyclerOptions
AllUsers
是您的POJO类,您需要进行查询才能包含在回收站适配器中.
AllUsers
is your POJO class, and you need to make a query to have in the recycler adapter.
更多信息在这里:
https://github.com/firebase/FirebaseUI-Android/tree /master/database
这篇关于如何使用FirebaseRecyclerAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!