本文介绍了从FirebaseRecyclerAdapter视图隐藏值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建类似于聊天应用程序的应用程序.现在,我不希望当前用户当前登录到设备的帐户显示在FirebaseRecyclerAdapter结果列表中.我具有当前用户UID.现在我只想从Adapter过滤当前的UID,怎么可能呢?预先感谢.
I'm creating an app similar to Chat app.Now I don't want current user which account currently logged in the device to show in FirebaseRecyclerAdapter result list.I've current user UID. Now I want to filter only this current UID from Adapter.How can it possible?Thanks in advance.
这是我的FirebaseRecyclerAdapter代码
Here is my FirebaseRecyclerAdapter code
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();
推荐答案
尝试一下:
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
this if Works hides the itemview
这篇关于从FirebaseRecyclerAdapter视图隐藏值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!