我需要从firebase recycleradapter获取组成员计数,但是我不知道该怎么做。由于我是android的新手,请帮助修复它。 我的代码可以很好地从数据库中检索所有组,但是我无法从单个组中获取成员计数并在每个组中显示它们。
每组的会员人数:
public class JoinGroup extends AppCompatActivity {
RecyclerView mGrouplist;
LinearLayoutManager mLayoutManager;
DatabaseReference mDatabase;
String groupRef,username;
String sub_push_Key;
String userId;
String groupname,groupphoto;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_join_group);
mGrouplist = findViewById(R.id.grouplist);
mGrouplist.setHasFixedSize(true);
// mpostlist.setLayoutManager(new LinearLayoutManager(PostList.this));
mLayoutManager = new LinearLayoutManager(this);
mLayoutManager.setReverseLayout(false);
mLayoutManager.setStackFromEnd(false);
// Now set the layout manager and the adapter to the RecyclerView
mGrouplist.setLayoutManager(mLayoutManager);
mDatabase = FirebaseDatabase.getInstance().getReference().child("AllGroups");
userId=FirebaseAuth.getInstance().getCurrentUser().getUid();
}
@Override
public void onStart() {
super.onStart();
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Loading Groups..");
progressDialog.setMessage("Please wait..");
progressDialog.setCancelable(false);
progressDialog.show();
如何在此处使用getItemCount方法:
final FirebaseRecyclerAdapter<GroupModel, JoinGroup.PostViewFolder> PSVF = new FirebaseRecyclerAdapter<GroupModel,JoinGroup.PostViewFolder>(
GroupModel.class,
R.layout.joingrouplayout,
JoinGroup.PostViewFolder.class,
mDatabase)
{
@Override
protected void populateViewHolder(final JoinGroup.PostViewFolder viewHolder, final GroupModel model, final int position) {
viewHolder.setGroupname(model.getGroupname());
viewHolder.setImageurl(getApplicationContext(),model.getImageurl());
progressDialog.cancel();
final String groupKey = getRef(position).getKey();
viewHolder.mview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
groupRef = groupKey;
groupname=model.getGroupname();
groupphoto=model.getImageurl();
// Toast.makeText(JoinGroup.this,"MEMBER " +String.valueOf(count),Toast.LENGTH_LONG).show();
joinGroup();
}
});
}
};
mGrouplist.setAdapter(PSVF);
}
public static class PostViewFolder extends RecyclerView.ViewHolder {
View mview;
public PostViewFolder(View itemView) {
super(itemView);
mview = itemView;
}
public void setGroupname(String groupname) {
TextView namegroup = (TextView) mview.findViewById(R.id.groupname);
namegroup.setText(groupname);
}
public void setImageurl(Context ctx, String imageurl) {
ImageView groupimage = mview.findViewById(R.id.groupimage);
Glide.with(ctx)
.load(imageurl)
.into(groupimage);
}
}