0

i wanna select in json data from my firebase database query like this statement

select * from timecheck where time = timeValue and date = dateValue

and i want to check the value and insert it in listview, but i don't know how to make it in firebase query

this is my Adapter

public class AppointmentAdapter extends BaseAdapter {

private Activity activity;
private List<Appointment> appointmentList;
LayoutInflater inflater;

public AppointmentAdapter(Activity activity, List<Appointment> appointments) {
    this.activity = activity;
    this.appointmentList = appointments;
    inflater = activity.getLayoutInflater();
}
@Override
public int getCount() {
    return appointmentList.size();
}
@Override
public Object getItem(int i) {
    return i;
}
@Override
public long getItemId(int i) {
    return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    LayoutInflater inflater = activity.getLayoutInflater();
    View listItemView = inflater.inflate(R.layout.list_view_time,null,true);
    TextView textViewTime = listItemView.findViewById(R.id.txt_time_list);
    ImageButton imageButtonCheck = listItemView.findViewById(R.id.img_time_list);
    Appointment appointment = appointmentList.get(i);
    textViewTime.setText(appointment.getTime_appointment());
    if (appointment.isActive_appointment()){
        imageButtonCheck.setEnabled(false);
        imageButtonCheck.setBackgroundResource(R.drawable.checked);
    }else {
        imageButtonCheck.setEnabled(true);
        imageButtonCheck.setBackgroundResource(R.drawable.check);
    }
    return null;
}
public void updateRecord(List<Appointment> appointments){
    this.appointmentList = appointments;
    notifyDataSetChanged();
}

}

and this is my firebase data

the node call appointment and i want to check date_appointment and time_appointment

"appointment" : {
    "-MH2n6VOOd-1AS95Yr52" : {
      "active_appointment" : "checked",
      "date_appointment" : "13/Aug/2020",
      "doctor_number" : "1",
      "id_appointment" : "-MH2n6VOOd-1AS95Yr52",
      "time_appointment" : "8:00 am"
    },
    "-MH2nEveOjSV4rAQ0hWJ" : {
      "active_appointment" : "checked",
      "date_appointment" : "13/Aug/2020",
      "doctor_number" : "1",
      "id_appointment" : "-MH2nEveOjSV4rAQ0hWJ",
      "time_appointment" : "8:00 am"
    },
    "-MH5eMK-gp3oTvMwavQn" : {
      "active_appointment" : "checked",
      "date_appointment" : "15/Aug/2020",
      "doctor_number" : "2",
      "id_appointment" : "-MH5eMK-gp3oTvMwavQn",
      "time_appointment" : "9:00 am"
    },
    "-MHA-5gV7x75PdPZcRZ4" : {
      "active_appointment" : "checked",
      "date_appointment" : "16/Aug/2020",
      "doctor_number" : "3",
      "id_appointment" : "-MHA-5gV7x75PdPZcRZ4",
      "time_appointment" : "9:00 am"
    },

my datasnap in my activity

 databaseRefrence_time = FirebaseDatabase.getInstance().getReference().child("appointment");
    appointmentList = new ArrayList<>();
    databaseRefrence_time.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot snapshot) {
            appointmentList.clear();
            for (DataSnapshot dataSnapshot : snapshot.getChildren()){
                Appointment appointment = dataSnapshot.getValue(Appointment.class);
                appointmentList.add(appointment);
            }
            AppointmentAdapter adapter = new AppointmentAdapter(booking.this,appointmentList);
            listView.setAdapter(adapter);
        }
        @Override
        public void onCancelled(@NonNull DatabaseError error) {
        }
    });
hanan
  • 1
  • 3
  • 2
    Nothing in this post is related to Firebase. Where are you querying the database? How is your db look like? – Alex Mamo Sep 17 '20 at 08:56
  • That's not possible with firebase to make this kind of request. ( And is not managed ) Only 2 ways, download all and filter on device. Build a crazy database with one key containing both value and all the possibility. Firebase suck at this kind of stuff. Forget about it. –  Sep 17 '20 at 10:20
  • i have update it and add the firebase database @AlexMamo – hanan Sep 17 '20 at 12:18
  • That's actually not possible. Check the duplicate to see a workaround. – Alex Mamo Sep 17 '20 at 12:40
  • first of all thank you soo much for replaying me and i want to ask you if you think i should use sqlite to do Query better together with frebase database .. ? and if your answer is yes then tell me how can i fetch firebase database to sqlit .. if you have any link or video that's helpful than pleaaaase help me @AlexMamo – hanan Sep 17 '20 at 15:08
  • Do you think i should use sqlite to do Query better together with frebase database .. ? and if your answer is yes then tell me how can i fetch firebase database to sqlit .. if you have any link or video that's helpful than pleaaaase help me @TeddySmith – hanan Sep 17 '20 at 15:09
  • There is no need for another database as Firebase has its own cache mechanism. – Alex Mamo Sep 17 '20 at 15:29
  • but i want to do query on the data not just to store it online @AlexMamo – hanan Sep 17 '20 at 15:35
  • This can be also achieved with Firebase. – Alex Mamo Sep 17 '20 at 15:55
  • then please tell me how i do it @AlexMamo like where statement – hanan Sep 17 '20 at 16:00
  • Like in the duplicate answer. – Alex Mamo Sep 17 '20 at 16:10

0 Answers0