Get Context in RecyclerView Adapter

May 5, 2019

Option 1: onBindViewHolder

override fun onBindViewHolder(holder: LocalAdapter.ViewHolder, position: Int) {
    val context = holder.itemView.context

}

Option 2: pass context from Activity/Fragment

class LocalAdapter(val context: Context): RecyclerView.Adapter<LocalAdapter.ViewHolder>() {

}
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.