我想创建一个列表视图,但是如果成员中存在当前用户ID,则显示状态,然后显示组名,这是屏幕截图中的test之类的键
列表视图有效,但是显示所有组,而我需要的是仅显示当前用户所属的组。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
groupFragmentView = inflater.inflate(R.layout.fragment_groups, container, false);
GroupRef = FirebaseDatabase.getInstance().getReference().child("Groups");
mGroupsList = (ListView) groupFragmentView.findViewById(R.id.list_view);
final ArrayAdapter arrayAdaptor = new ArrayAdapter<String>(getContext(),android.R.layout.simple_list_item_1,mGroups);
mGroupsList.setAdapter(arrayAdaptor);
mGroupsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id)
{
String currentGroupName = adapterView.getItemAtPosition(position).toString();
Intent groupChatIntent=new Intent(getContext(),GroupChatActivity.class);
groupChatIntent.putExtra("groupName",currentGroupName);
startActivity(groupChatIntent);
}
});
GroupRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
String value = dataSnapshot.getKey();
String currentUser= mAuth.getUid();
UserRef = GroupRef.child(value).child("Group Details").orderByChild("Members").equalTo(currentUser);
mGroups.add(value);
arrayAdaptor.notifyDataSetChanged();
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});