我在项目中使用FirebaseRecyclerAdapter,并且可以通过以下键从firebase中获取数据:
private String title;
private String desc;
private String image;
private String url;
private int id;
但是如果使用此键,我不会从Firebase获取数据
private String classname;
private id classno;
FirebaseRecyclerAdapter代码;
DatabaseReference personsRef = FirebaseDatabase.getInstance().getReference().child("users");
Query personsQuery = personsRef.orderByKey();
mPeopleRV.hasFixedSize();
int numberOfColumns = 1;
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getApplicationContext(), numberOfColumns);
mPeopleRV.setLayoutManager(mLayoutManager);
FirebaseRecyclerOptions personsOptions = new FirebaseRecyclerOptions.Builder<Data>().setQuery(personsQuery, Data.class).build();
mPeopleRVAdapter = new FirebaseRecyclerAdapter<Data, NewsViewHolder>(personsOptions) {
@Override
protected void onBindViewHolder(MainActivity.NewsViewHolder holder, final int position, final Data model) {
holder.setTitle(model.getTitle());
}
@Override
public MainActivity.NewsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.users_row, parent, false);
return new MainActivity.NewsViewHolder(view);
}
};
mPeopleRV.setAdapter(mPeopleRVAdapter);
Data.class
public class Data {
private String title;
private String image;
private int id;
private String classname;
private int classno;
public String getTitle() {
return title;
}
public String getImage() {
return image;
}
public int getId() {
return id;
}
public String getClassname() {
return classname;
}
public int getClassno() {
return classno;
}
}
我想使用“ classname”和“ classno”键获取数据。我怎样才能做到这一点?谢谢。