Как получить данные о ребенке ребенка в базе данных, как на картинке?Я пытался, но получаю ошибку
это мой фрагмент активности для получения данных
package com.fish.isyania.aplikasipemesananreparasi.fragment
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ListView
import android.widget.Toast
import com.fish.isyania.aplikasipemesananreparasi.R
import com.fish.isyania.aplikasipemesananreparasi.adapter.OrderAdapter
import com.fish.isyania.aplikasipemesananreparasi.model.Order
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.*
import kotlinx.android.synthetic.main.fragment_order_list.view.*
class OrderListFragment : Fragment() {
lateinit var ref : DatabaseReference
lateinit var refChild : DatabaseReference
lateinit var orderList : MutableList<Order>
lateinit var listView : ListView
var user = FirebaseAuth.getInstance().currentUser
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val rootView = inflater.inflate(R.layout.fragment_order_list, container, false)
var uid = user!!.uid
orderList = mutableListOf()
ref = FirebaseDatabase.getInstance().getReference("Order")
ref.child(uid).addValueEventListener(object : ValueEventListener {
override fun onCancelled(p0: DatabaseError?) {
Toast.makeText(context,"sorry", Toast.LENGTH_LONG ).show()
}
override fun onDataChange(p0: DataSnapshot?) {
if(p0!!.exists()){
orderList.clear()
for(h in p0.children){
val order = h.getValue(Order::class.java)
orderList.add(order!!)
}
val adapter = OrderAdapter(context!!, R.layout.order_row, orderList)
rootView.listView.adapter = adapter
}
}
})
return rootView
}
companion object {
fun newInstance(): OrderListFragment = OrderListFragment()
}
}
это моя модель
package com.fish.isyania.aplikasipemesananreparasi.model
class Order (val alamat : String, val harga : Long, val jenisPemesanan : String, val keterangan : String, val nama : String, val namaTeknisi : String,
val noTeleponTeknisi : String, val nomorPesanan : String, val nomorTelepon : String, val status : String
) {
constructor() : this("", 0, "","","","","","","",
"")
}
это мой адаптер
package com.fish.isyania.aplikasipemesananreparasi.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import com.fish.isyania.aplikasipemesananreparasi.R
import com.fish.isyania.aplikasipemesananreparasi.model.Order
class OrderAdapter(val mCtx : Context, val layoutResId : Int, val orderList : List<Order>) : ArrayAdapter<Order>(mCtx, layoutResId, orderList) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
val layoutInflater : LayoutInflater = LayoutInflater.from(mCtx)
val view : View = layoutInflater.inflate(layoutResId, null)
val nomorPesanan = view.findViewById<TextView>(R.id.nomorPesanan)
val namaPemesan = view.findViewById<TextView>(R.id.namaPemesan)
val alamatPemesan = view.findViewById<TextView>(R.id.alamatPemesan)
val jenisPemesanan = view.findViewById<TextView>(R.id.jenisPemesanan)
val namaTeknisi = view.findViewById<TextView>(R.id.namaTeknisi)
val statusPemesanan = view.findViewById<TextView>(R.id.statusPemesanan)
var harga = view.findViewById<TextView>(R.id.hargaPemesanan)
val order = orderList[position]
var hargaPemesanan = order.harga
nomorPesanan.text = "Nomor Pesanan: " + order.nomorPesanan
namaPemesan.text = "Nama Pemesan: " + order.nama
alamatPemesan.text = "Alamat Pemesan: " + order.alamat
jenisPemesanan.text = "Jenis Pemesanan: " +order.jenisPemesanan
namaTeknisi.text = "Nama Teknisi: " + order.namaTeknisi
statusPemesanan.text ="Status Pemesanan" + order.status
harga.text = "Harga: " + hargaPemesanan.toString() + "(belum termasuk biaya pergantian suku cadang bila diperlukan)"
return view
}
}
Как я могу получить данные от child of child в firebase, как на картинке?