Get Data from firestore in Android Studio with Kotlin.

Kumar Shubhankar
1 min readFeb 2, 2021
  • We have use a one data model, Activity and one xml file.
  • will add a dependency for .

Hi everyone:

ActivityMain.kt:

class AppointmentCompleteActivity : AppCompatActivity() {

private var db = FirebaseFirestore.getInstance()
lateinit var appointmentCompleteDoctorImage: CircleImageView
lateinit var appointmentCompleteDoctorName: TextView
lateinit var appointmentCompleteDoctorSpecialistName: TextView
lateinit var appointmentCompleteHospitalName: TextView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_apponitment_complete)

appointmentCompleteDoctorImage = findViewById(R.id.appointmentComplete_doctorImage)
appointmentCompleteDoctorName = findViewById(R.id.appointmentCompleteDoctorName)
appointmentCompleteDoctorSpecialistName = findViewById(R.id.appointmentCompleteSpecialistName)
appointmentCompleteHospitalName = findViewById(R.id.appointmentComplateHospitalName)

doctorRetrieveData()

}

private fun doctorRetrieveData() {
db.collection("booking")..document("your document")
.get()
.addOnSuccessListener {
val data = it.toObjects(DoctorSlotsModel::class.java)
val items = data.size
if (items > 0){
for (item in data){
// val doctorCompleteImage = item.profileImage
val doctorCompleteName = item.doctor?.firstName+ " "+ item.doctor?.lastName
val doctorComplete = item.doctor?.speciality
val doctorCompleteHospitalName = "AIIMS PATNA"

appointmentCompleteDoctorName.text = doctorCompleteName
appointmentCompleteDoctorSpecialistName.text = doctorComplete
appointmentCompleteHospitalName.text = doctorCompleteHospitalName
}
}
}
}

I have create a collection (booking), it has create different sub-collection and different type of field. I have select a three fields. it is receive data in android Studio from data class models. it is create a private function and one create private a variable.

thanks for reading…

--

--