I'm trying to Retrieve data from Firebase database and storage into a RecyclerView and CardView , i don't get any error on the code but when i run the application nothing shows up and i get a message in the run like this (V/FA: Inactivity, disconnecting from the service I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@c2f66cf time:168073912 ) i have tried many solutions like this one here V/FA: Inactivity, disconnecting from the service but it didn't workout with me
my photo folder in firebase database name /doctor_images
this is my class Doctor
public class Doctor {
private String Doctor_ID;
private String Doctor_Name;
private String Doctor_Email;
private String Doctor_Phone;
private String Doctor_Speciality;
private int Doctor_Rating;
private String Doctor_Image_Url;
public String getDoctor_ID() {
return Doctor_ID;
}
public void setDoctor_ID(String doctor_ID) {
Doctor_ID = doctor_ID; }
public String getDoctor_Name() {
return Doctor_Name; }
public void setDoctor_Name(String doctor_Name) {
Doctor_Name = doctor_Name; }
public String getDoctor_Email() {
return Doctor_Email; }
public void setDoctor_Email(String doctor_Email) {
Doctor_Email = doctor_Email; }
public String getDoctor_Phone() {
return Doctor_Phone; }
public void setDoctor_Phone(String doctor_Phone) {
Doctor_Phone = doctor_Phone; }
public String getDoctor_Speciality() { return Doctor_Speciality; }
public void setDoctor_Speciality(String doctor_Speciality) {
Doctor_Speciality = doctor_Speciality; }
public int getDoctor_Rating() {
return Doctor_Rating; }
public void setDoctor_Rating(int doctor_Rating) {
Doctor_Rating = doctor_Rating; }
public String getDoctor_Image_Url() {
return Doctor_Image_Url; }
public void setDoctor_Image_Url(String doctor_Image_Url) {
Doctor_Image_Url = doctor_Image_Url; }
public Doctor(String doctor_ID, String doctor_Name, String doctor_Email, String doctor_Phone, String doctor_Speciality, int doctor_Rating, String doctor_Image_Url) {
Doctor_ID = doctor_ID;
Doctor_Name = doctor_Name;
Doctor_Email = doctor_Email;
Doctor_Phone = doctor_Phone;
Doctor_Speciality = doctor_Speciality;
Doctor_Rating = doctor_Rating;
Doctor_Image_Url = doctor_Image_Url; }
public Doctor() { }
}
and my Adapter code is this
public class DoctorAdapter extends RecyclerView.Adapter<DoctorAdapter.DoctorViewHolder> {
private Context mcontext;
private List<Doctor> mDoctor;
public DoctorAdapter (Context context , List<Doctor> doctors){
mcontext = context;
mDoctor = doctors; }
@NonNull
@Override
public DoctorViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mcontext).inflate(R.layout.image_doctor,parent,false);
return new DoctorViewHolder(v); }
@Override
public void onBindViewHolder(@NonNull DoctorViewHolder holder, int position) {
Doctor doctorCurrent = mDoctor.get(position);
holder.txtNameDoctor.setText(doctorCurrent.getDoctor_Name());
holder.txtSpecialityDoctor.setText(doctorCurrent.getDoctor_Speciality());
Picasso.with(mcontext)
.load(doctorCurrent.getDoctor_Image_Url())
.fit()
.centerCrop()
.into(holder.imgDoctor); }
@Override
public int getItemCount() {
return mDoctor.size(); }
public class DoctorViewHolder extends RecyclerView.ViewHolder{
public TextView txtNameDoctor;
public TextView txtSpecialityDoctor;
public ImageView imgDoctor;
public DoctorViewHolder(@NonNull View itemView) {
super(itemView);
txtNameDoctor = itemView.findViewById(R.id.doctor_name_recycler_card);
txtSpecialityDoctor = itemView.findViewById(R.id.doctor_Speciality_recycler_card);
imgDoctor = itemView.findViewById(R.id.doctor_image_recycler_card); }
}
}
and my card Layout
<LinearLayout
android:id="@+id/container_all_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="10dp"
android:background="@drawable/card_shape"
>
<ImageView
android:id="@+id/doctor_image_recycler_card"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="5dp"/>
<LinearLayout
android:layout_marginTop="5dp"
android:id="@+id/container_text_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_marginTop="10dp"
android:id="@+id/doctor_name_recycler_card"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#ffffff" />
<TextView
android:id="@+id/doctor_Speciality_recycler_card"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
and this is my RecyclerView in my Layout
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycle_search_doctor"
android:layout_width="match_parent"
android:layout_height="match_parent" />
and this is my Activity java class
public class AllDoctorActivity extends AppCompatActivity {
private RecyclerView mRecyclerView ;
private DatabaseReference mdatabaseReference;
private DoctorAdapter mdoctorAdapter;
private List<Doctor> mdoctors;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_doctor);
mRecyclerView = findViewById(R.id.recycle_search_doctor);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mdoctors = new ArrayList<>();
mdatabaseReference = FirebaseDatabase.getInstance().getReference("doctors");
mdatabaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot postSnapShot : snapshot.getChildren()){
Doctor doctor = postSnapShot.getValue(Doctor.class);
mdoctors.add(doctor);
}
mdoctorAdapter = new DoctorAdapter(AllDoctorActivity.this,mdoctors);
mRecyclerView.setAdapter(mdoctorAdapter);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
Toast.makeText(AllDoctorActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
}
this is my doctor json code
"doctors" : {
"-MEOD5GJqtMUR6V4XGbO" : {
"-MGmxz1j6vmSzK0DlExJ" : {
"doctor_Email" : "576",
"doctor_Image_Url" : "https://firebasestorage.googleapis.com/v0/b/my-appointment-240f3.appspot.com/o/doctor_images%2F-MGmxz1j6vmSzK0DlExJ.jpg?alt=media&token=eb9e2cb5-af19-47de-b634-d08ce5cb0184",
"doctor_Name" : "yyyy",
"doctor_Phone" : "756",
"doctor_Rating" : "3",
"doctor_Speciality" : "756"
},
"-MGmy0tSdXTq4X0Nhqpb" : {
"doctor_Email" : "576",
"doctor_Image_Url" : "https://firebasestorage.googleapis.com/v0/b/my-appointment-240f3.appspot.com/o/doctor_images%2F-MGmy0tSdXTq4X0Nhqpb.jpg?alt=media&token=28ca5065-4b2f-41ff-a9b2-e8618362dc2d",
"doctor_Name" : "yyyy",
"doctor_Phone" : "756",
"doctor_Rating" : "3",
"doctor_Speciality" : "756"
}
}
}
and this is my hospital json code
"hospitals" : {
"-MEOD5GJqtMUR6V4XGbO" : {
"hospital_address" : "شارع بغداد",
"hospital_name" : "عبد القادر المتوكل",
"hospital_number" : "777777",
"hospital_phone" : "7777777",
"id" : "-MEOD5GJqtMUR6V4XGbO"
},
"-MGN5Lno-SA7b50ACOpK" : {
"hospital_address" : "شارع الزبيري",
"hospital_name" : "الجمهوري",
"hospital_number" : "555555",
"hospital_phone" : "77555555",
"id" : "-MGN5Lno-SA7b50ACOpK"
},
"-MGOHrjqhGZ8EjeGHPjW" : {
"hospital_address" : "الستين",
"hospital_name" : "ازال",
"hospital_number" : "88888",
"hospital_phone" : "888888",
"id" : "-MGOHrjqhGZ8EjeGHPjW"
}
}