我目前正在使用管理员用户使用我的论坛应用程序。 是否可以在RecyclerView中显示不同的父级及其子级?
在我目前的代码中,我使用了switch但它只显示了最后一个开关。 这是我的代码
protected void onStart() {
super.onStart();
mDatabaseG1S1 = FirebaseDatabase.getInstance().getReference().child("Grade1Section1");
mDatabaseG1S2 = FirebaseDatabase.getInstance().getReference().child("Grade1Section2");
mDatabase = FirebaseDatabase.getInstance().getReference().child("Grade1Section3");
int ctr = 0;
mAuth.addAuthStateListener(mAuthListener);
switch(ctr)
{case 0: FirebaseRecyclerAdapter<Blog, BlogViewHolder> firebaseRecyclerAdapter
= new FirebaseRecyclerAdapter<Blog, BlogViewHolder>(
Blog.class,
R.layout.outer_row,
BlogViewHolder.class,
mDatabase)
{
@Override
protected void populateViewHolder(final BlogViewHolder viewHolder, final Blog model, final int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDesc());
viewHolder.setUsername(model.getUsername());
}
};
mBlogList.setAdapter(firebaseRecyclerAdapter);
}
switch(ctr)
{
case 0: FirebaseRecyclerAdapter<Blog, BlogViewHolder> firebaseRecyclerAdapter
= new FirebaseRecyclerAdapter<Blog, BlogViewHolder>(
Blog.class,
R.layout.outer_row,
BlogViewHolder.class,
mDatabaseG1S1 )
{
@Override
protected void populateViewHolder(final BlogViewHolder viewHolder, final Blog model, final int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDesc());
viewHolder.setUsername(model.getUsername());
}
};
mBlogList.setAdapter(firebaseRecyclerAdapter);
}
switch(ctr)
{
case 0: FirebaseRecyclerAdapter<Blog, BlogViewHolder> firebaseRecyclerAdapter
= new FirebaseRecyclerAdapter<Blog, BlogViewHolder>(
Blog.class,
R.layout.outer_row,
BlogViewHolder.class,
mDatabaseG1S2 )
{
@Override
protected void populateViewHolder(final BlogViewHolder viewHolder, final Blog model, final int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDesc());
viewHolder.setUsername(model.getUsername());
}
};
mBlogList.setAdapter(firebaseRecyclerAdapter);
}
}
它只显示最后一个开关,即Grade1Section1父项及其子项
我想在RecyclerView中显示这些父母的子女。