Skip to content

Instantly share code, notes, and snippets.

@mwshubham
Last active November 7, 2021 11:23
Show Gist options
  • Save mwshubham/ff835e604b90de2925cd227108704b53 to your computer and use it in GitHub Desktop.
Save mwshubham/ff835e604b90de2925cd227108704b53 to your computer and use it in GitHub Desktop.
RealmRecyclerViewAdapter example in kotlin using Realm Results and autoUpdate property
class HomeListAdapter(val context: Context, contactBeans: RealmResults<ContactBean>?, val realmInstance: Realm, autoUpdate: Boolean)
: RealmRecyclerViewAdapter<ContactBean, HomeListAdapter.ViewHolder>(contactBeans, autoUpdate) {
val TAG = HomeListAdapter::class.simpleName
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.item_chat, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
}
override fun getItemCount(): Int {
return if (data == null) 0 else data!!.size
}
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
}
@DVegasa
Copy link

DVegasa commented Mar 10, 2019

Please, change the name of file to
kotlin_realm_rv_adapter_auto_update_demo.kt

to let GitHub highlight the kotlin syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment