目前,我能够列出所有医生预约的清单,以供所有患者查看。但是我需要设置为当前登录系统的患者只能看到他的约会以及他的名字。如何查询?我正在使用Firebase实时数据库和android studio。
我用于查看患者约会的代码:
package com.example.myapplication;
import android.os.Bundle;
import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.widget.SearchView;
import android.widget.Toast;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
public class patapp extends Activity {
DatabaseReference ref;
ArrayList<Booking> list1;
RecyclerView recyclerView;
SearchView searchView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_patapp);
ref = FirebaseDatabase.getInstance().getReference().child("Bookings");
recyclerView = findViewById(R.id.rvpat);
searchView = findViewById(R.id.svp);
}
@Override
protected void onStart() {
super.onStart();
if (ref != null)
{
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists())
{
list1 = new ArrayList<>();
for (DataSnapshot ds : dataSnapshot.getChildren())
{
list1.add(ds.getValue(Booking.class));
}
adapterclass1 Adapterclass = new adapterclass1(patapp.this,list1);
//
//
//
recyclerView.setAdapter(Adapterclass);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(patapp.this, databaseError.getMessage(),Toast.LENGTH_SHORT).show();
}
});
}
if (searchView != null)
{
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public boolean onQueryTextChange(String s) {
search(s);
return true;
}
});
}
}
private void search(String str)
{
ArrayList<Booking> myList = new ArrayList<>();
for (Booking object : list1)
{
if (object.getPatname().toLowerCase().contains(str.toLowerCase()))
{
myList.add(object);
}
}
adapterclass1 Adapterclass = new adapterclass1(patapp.this,myList);
//
//
//
recyclerView.setAdapter(Adapterclass);
}
}
答案 0 :(得分:0)
databaseReference=FirebaseDatabase.getInstance().getReference("Bookings");
final Query findfeedback=databaseReference.orderByChild("email")
.equalTo(Booking.getEmail);
findfeedback.addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
{
for (DataSnapshot Bookings: dataSnapshot.getChildren())
{
do something
}
});
}