我正在创建一个类似于聊天应用的应用。现在我不希望当前用户当前登录设备的帐户显示在FirebaseRecyclerAdapter结果列表中。我是当前用户的UID。现在我想从Adapter中仅过滤当前的UID。如果可能的话? 提前谢谢。
这是我的FirebaseRecyclerAdapter代码
FirebaseRecyclerAdapter<Donors, DonorsViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Donors, DonorsViewHolder>(
Donors.class,
R.layout.donors_single_layout,
DonorsViewHolder.class,
mUsersDatabase.orderByChild("search").equalTo(searchKey)
) {
@Override
protected void populateViewHolder(DonorsViewHolder viewHolder, Donors model, int position) {
viewHolder.setName(model.getName());
viewHolder.setLocation(model.getLocation());
viewHolder.setImage(model.getThumb_image(), getApplicationContext());
viewHolder.setGroup(model.getGroup());
final String donorID = getRef(position).getKey();
//WANTED TO HIDE THIS WAY BUT THAT DOESN"T WORK :(
if(donorID == mCurrentUserId){
viewHolder.setIsRecyclable(false);
return;
}
}
};
mDonorsList.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.notifyDataSetChanged();
答案 0 :(得分:0)
试试这个:
viewHolder.setVisibility(View.INVISIBLE);
您的代码是这样的:
if(donorID == mCurrentUserId){
viewHolder.setIsRecyclable(false);
viewHolder.setVisibility(View.INVISIBLE);
return;
}
或强>:
viewHolder.setVisibility(View.GONE);
所以代码是这样的:
if(donorID == mCurrentUserId){
viewHolder.setIsRecyclable(false);
viewHolder.setVisibility(View.GONE);
return;
}
如果Works隐藏了 itemview