Postingan lainnya
Search dari recycleview caranya gimana ya. kotlin firebase
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_recycle_motor)
supportActionBar!!.title = "List Motor"
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
fetchmotor()
searchmotor.setHint("Search.....")
searchmotor.addTextChangeListener(object : TextWatcher {
override fun afterTextChanged(p0: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
val searchtext = searchmotor.text.toString().toUpperCase()
}
})
}
private fun fetchmotor() {
val ref = FirebaseDatabase.getInstance().getReference("/Motor")
ref.addListenerForSingleValueEvent(object: ValueEventListener {
override fun onDataChange(p0: DataSnapshot) {
val listrecycle = GroupAdapter<ViewHolder>()
p0.children.forEach {
val motor = it.getValue(motor::class.java)
if (motor != null) {
listrecycle.add(motorItem(motor))
}
}
MotorRecycleview.adapter = listrecycle
}
override fun onCancelled(p0: DatabaseError) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
})
}
}
class motorItem(val motor: motor): Item<ViewHolder>() {
override fun bind(viewHolder: ViewHolder, position: Int) {
viewHolder.itemView.Mnopol.text = motor.nopolisi
viewHolder.itemView.Mnama.text = motor.nama
}
override fun getLayout(): Int {
return R.layout.designmotor
}
}
0
Tanggapan
coba bertanya dengan baik, baca aturan main
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban