从Firebase中显示RecyclerView中当前用户以外的所有用户

时间:2017-07-12 23:31:04

标签: java android firebase firebase-realtime-database firebaseui

我正在尝试从Firebase获取除Recyclerview中当前用户之外的用户列表。如何从recyclerview过滤当前用户?

Here是我的Firebase数据。如果当前用户是" Praveen Chowdary"我应该得到" Srikar"在我的Recyclerview中。

这是我的JAVA文件

public class FriendsFragment extends Fragment {

RecyclerView recyclerView;
DatabaseReference dbreference;
StorageReference sreference;
FirebaseUser currentUser;
FirebaseAuth fbAuth;
View v;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    Context c = getContext();
    v = inflater.inflate(R.layout.friends_fragment_layout, null);
    recyclerView = (RecyclerView) v.findViewById(R.id.rview);
    recyclerView.setHasFixedSize(true);

    dbreference = FirebaseDatabase.getInstance().getReference().child("Users");

    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    fbAuth = FirebaseAuth.getInstance();
    currentUser = fbAuth.getCurrentUser();
    return v;
}

@Override
public void onStart() {
    super.onStart();

    final String uid = currentUser.getUid();
    FirebaseRecyclerAdapter<UserElements, UserViewHolder> fbradapter = new FirebaseRecyclerAdapter<UserElements, UserViewHolder>(
            UserElements.class,
            R.layout.members_row_model,
            UserViewHolder.class,
            dbreference
    ) {
        @Override
        protected void populateViewHolder(UserViewHolder viewHolder, UserElements model, int position) {


                viewHolder.setTitle(model.getName());
                viewHolder.setDescription(model.getMobile());
                viewHolder.setImage(getActivity(), model.getProfilepic());

        }
    };

    recyclerView.setAdapter(fbradapter);

}


public static class UserViewHolder extends RecyclerView.ViewHolder{
    View view;
    public UserViewHolder(View itemView) {
        super(itemView);
        view = itemView;
    }

    public void setTitle(String title){
        TextView user = (TextView) view.findViewById(R.id.userName);
        user.setText(title);
    }
    public void setDescription(String desc){
        TextView mobile = (TextView) view.findViewById(R.id.userNumber);
        mobile.setText(desc);
    }
    public void setImage(final Context ctx, final String image){
        final CircleImageView profilePic = (CircleImageView) view.findViewById(R.id.userPic);
        Picasso.with(ctx).load(image).into(profilePic);
    }
}

}

这是我的UserElements.java

public class UserElements {
private String mobile, name, profilepic;

public UserElements(String mobile, String name, String profilepic) {
    this.mobile = mobile;
    this.name = name;
    this.profilepic = profilepic;
}

public UserElements(){}

public String getMobile() {
    return mobile;
}

public void setMobile(String mobile) {
    this.mobile = mobile;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getProfilepic() {
    return profilepic;
}

public void setProfilepic(String profilepic) {
    this.profilepic = profilepic;
}

}

请帮帮我..

提前致谢。

0 个答案:

没有答案