问题
I am making a chat app in which I have groups. The admin chooses who are there and others can't see it. I can hide it. but the one below is showing the one above it. thus I decided to delete it from the recycler view. but I don't want to delete it from firebase because the group should be visible to others who are in the group.
I have googled and searched StackOverflow, no one had seemed to come across my issue. tried other sorts of stuff but nothing worked out. Is there any way I can remove it? or Is the only option to remove it by firebase?
edit:
new FirebaseRecyclerOptions.Builder<Groups>()
.setQuery(GroupsRef, Groups.class)
.build();
final FirebaseRecyclerAdapter<Groups, groupsViewHolder>
adapter = new FirebaseRecyclerAdapter<Groups, groupsViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull final groupsViewHolder groupsViewHolder, final int i, @NonNull Groups groups)
{
final String string = getRef(i).getKey();
if (string != null) {
GroupsRef
.child(string)
.child("Users")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
{
if (dataSnapshot.exists())
{
if (dataSnapshot.hasChild(UID))
{
groupsViewHolder.itemView.setVisibility(View.VISIBLE);
GroupsRef
.child(string)
.child("Group info").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
{
String name = Objects.requireNonNull(dataSnapshot.child("group name").getValue()).toString();
groupsViewHolder.Username.setText(name);
if (dataSnapshot.hasChild("group image")) {
String image = Objects.requireNonNull(dataSnapshot.child("group image").getValue()).toString();
Picasso.get().load(image).placeholder(R.drawable.profile_image).into(groupsViewHolder.profileImageView);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
groupsViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Intent mainIntent = new Intent(getContext(), GroupChatActivity.class);
mainIntent.putExtra("groupUID", string);
startActivity(mainIntent);
}
});
}
else {
groupsViewHolder.itemView.setVisibility(View.INVISIBLE);
notifyItemRemoved(i);
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
@NonNull
@Override
public groupsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
{
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.groups, parent, false);
return new groupsViewHolder(view);
}
};
myRecyclerList.setAdapter(adapter);
adapter.startListening();
GroupsRef
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
{
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
This is how it looks for the person who is in the group. here This is how it looks for the person not in the group. here
sorry for links as 10 reputation to post images
edit: I have 10 reputation now so the images are:
来源:https://stackoverflow.com/questions/57294639/how-to-delete-item-from-firebaserecyclerview-without-actually-deleting-it-in-fir