我正在尝试使用FirebaseRecyCyclerAdapter在我的Android应用程序上查看数据库信息,但是在我期望PopulateViewHolder方法的地方,我会得到其他两个弹出。代码如下:
FirebaseRecyclerAdapter<NoteModel, NoteViewHolder> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter<NoteModel, NoteViewHolder>(
NoteModel.class,
R.layout.single_note_layout,
NoteViewHolder.class,
fNotesDatabase
) {
@Override
public NoteViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return null;
}
@Override
protected void onBindViewHolder(@NonNull NoteViewHolder holder, int position, @NonNull NoteModel model) {
}
};
}
公共Noteviewholder和受保护的无效void onbindviewholder并不是过去在使用FirebaseReccyleradapater之后的过去,这两者尚未出现。我期待:
protected void populateViewHolder ( NoteViewHolder viewHolder, NoteModel model, int position) {
}
有人有任何想法,为什么不再可用?我不确定如何完成代码,因为我以前从未见过这样的代码。我需要添加....
String noteId = getRef(position).getKey();
....但是我不知道在哪里。
预先感谢。
firebaseui迁移指南是一个很好的起点。本质上,您需要做这样的事情:
FirebaseRecyclerOptions<NoteModel> options = new FirebaseRecyclerOptions.Builder<>()
.setQuery(fNotesDatabase, NoteModel.class)
.build();
FirebaseRecyclerAdapter<NoteModel, NoteViewHolder> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter<NoteModel, NoteViewHolder>(options) {
@Override
public NoteViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new NoteViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.single_note_layout, parent, false));
}
@Override
protected void onBindViewHolder(@NonNull NoteViewHolder holder,
int position,
@NonNull NoteModel model) {
String key = getSnapshots().getSnapshot(position).getKey();
holder.bind(...);
}
};