An Android libs for recyclerview adapter including support filterable data for searchview or material search bar. So you don't need to create class adapter if want to use recyclerview.
Sebuah library Android untuk adapter recyclerview termasuk mendukung filterable data untuk penggunaan searchview atau material search bar. Jadi anda tidak perlu membuat class adapter jika ingin menggunakan recyclerview.
Support from Android 4.4 KitKat / Minimum API 19
Dukungan mulai Android versi 4.4 KitKat / Minimal API 19
Add repository in build.gradle
Tambahkan repository di build.gradle
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
And add dependencies
Dan tambahkan dependencies
dependencies {
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.github.azmirizkifar20:reusable-recyclerview-adapter:1.0.3'
}
val adapterCallback = object : AdapterCallback<Model> {
override fun initComponent(itemView: View, data: Model, itemIndex: Int) {
// init component here
}
override fun onItemClicked(itemView: View, data: Model, itemIndex: Int) {
// add logic here
}
}
// setup adapter
ReusableAdapter<Model>(this)
.adapterCallback(adapterCallback)
.setLayout(R.layout.example_layout)
.addData(listData)
.isVerticalView()
.build(recyclerview)
// #1 create reusable-adapter
ReusableAdapter<Model>(context: Context)
// #2 adapter callback (required)
adapterCallback(adapterCallback: AdapterCallback<Model>)
// #3 set layout of recyclerview (required)
setLayout(layout: Int)
// #4 set orientation view (required) [choose one]
isVerticalView()
isHorizontalView()
// #5 add list of data (required)
addData(listData: List<Model>)
// #6 update data for realtime change (optional)
updateData(data: Model)
// #7 filterable for searchview (optional)
filterable()
// #8 the last and required component
build(recyclerView: RecyclerView)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="vertical">
<TextView
android:id="@+id/tv_nama_negara"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama negara"
android:textColor="@android:color/black"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_ibukota"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ibukota"
android:textSize="16sp" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_negara"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/item_negara" />
data class Negara (
val nama_negara: String,
val ibukota: String
)
val listNegara = listOf(
Negara("Indonesia", "jakarta"),
Negara("Malaysia", "Kuala Lumpur"),
Negara("Thailand", "Bangkok"),
Negara("Vietnam", "Hanoi"),
Negara("Filipina", "Manila")
)
// create adapter callback for init component
val adapterCallback = object : AdapterCallback<Negara> {
override fun initComponent(itemView: View, data: Negara, itemIndex: Int) {
itemView.tv_nama_negara.text = data.nama_negara
itemView.tv_ibukota.text = data.ibukota
}
override fun onItemClicked(itemView: View, data: Negara, itemIndex: Int) {
Toast.makeText(this@MainActivity, data.nama_negara, Toast.LENGTH_SHORT).show()
}
}
// setup adapter
ReusableAdapter<Negara>(this)
.adapterCallback(adapterCallback)
.setLayout(R.layout.item_negara)
.addData(listNegara)
.isVerticalView()
.build(rv_negara)
Give a star and fork if this project helped you!