【发布时间】:2022-01-27 18:25:27
【问题描述】:
我的应用在 firebaseRecycler Adapter 中显示所有的 firebase 数据。我想从显示中排除当前在线用户的数据。例如,Ibad Ullah 登录到应用程序,然后他的数据不得显示在回收站视图中。我使用 Query orderByChild 但它隐藏了所有用户数据。我怎样才能做到这一点?谢谢你。下面是我的代码。
仪表板活动
if(fAuth.getCurrentUser() != null){
UID = FirebaseAuth.getInstance().getCurrentUser().getUid();
}
dRef.child(UID).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
remainingClicks = String.valueOf(snapshot.child("clicksRemain").getValue(Integer.class));
showGigCount = String.valueOf(snapshot.child("showGigCount").getValue(Integer.class));
fiverrLink1 = (String) snapshot.child("gig").getValue();
String username = (String) snapshot.child("name").getValue();
clicks.setText(remainingClicks);
userName.setText(username);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
recyclerView = findViewById(R.id.dashboardRCV);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
LoadData();
}
private void LoadData() {
options = new FirebaseRecyclerOptions.Builder<ModelClass>()
.setQuery(dRef, ModelClass.class)
.build();
adapter = new FirebaseRecyclerAdapter<ModelClass, MyViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull MyViewHolder holder, int position, @NonNull ModelClass model) {
if (dRef.child(UID).child("clicksRemain").equals(0)){
zeroClicks.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
}
holder.previewLink.setURL(model.getGig(), new URLEmbeddedView.OnLoadURLListener() {
@Override
public void onLoadURLCompleted(URLEmbeddedData data) {
holder.previewLink.title(data.getTitle());
holder.previewLink.description(data.getDescription());
holder.previewLink.host(data.getHost());
holder.previewLink.thumbnail(data.getThumbnailURL());
holder.previewLink.favor(data.getFavorURL());
}
});
//This will hide the gig if its showGigCount becomes 0
Query query = dRef.orderByChild("showGigCount").equalTo(0);
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()){
holder.previewLink.setVisibility(View.GONE);
}else{
holder.previewLink.setVisibility(View.VISIBLE);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
};
query.addListenerForSingleValueEvent(valueEventListener);
holder.previewLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// String profileLink = getRef(position).child(model.getGig()).toString();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(model.getGig()));
startActivity(browserIntent);
}
});
【问题讨论】:
-
为了更好地理解,您想从“用户”中获取除已登录的用户之外的所有用户?
-
@AlexMamo 是的,我想隐藏当前在线用户的所有数据。
标签: android firebase-realtime-database android-recyclerview firebaseui