Last active
June 11, 2022 15:03
-
-
Save Rahul-Chauhan21/0c81b857e1a8cf82e6200bbe8000fb72 to your computer and use it in GitHub Desktop.
RecyclerView Adapter Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.example.<app-name>.model.<T> | |
/** | |
Adapter for [RecyclerView] in [Activity]. Displays [dataset] data objects. | |
*/ | |
class ItemAdapter( | |
private val context: Context, | |
private val dataset: List<T> | |
) : RecyclerView.Adapter<ItemAdapter.ItemViewHolder>() { | |
// Provide a reference to the views for each data item | |
// Complex data items may need more than one view per item, and | |
// you provide access to all the views for a data item in a view holder. | |
class ItemViewHolder(private val view: View) : RecyclerView.ItemViewHolder(view) { | |
val loremView : <T> = view.findViewById({id}) | |
} | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { | |
val adapterLayout = LayoutInflator.from(parent.context) | |
.inflate({id}, parent, false) | |
return ItemViewHolder(adapterLayout) | |
} | |
override fun getItemCount() = dataset.size | |
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { | |
val item = dataset[position] | |
//set value of the view -> holder.loremView.{property} = item.{property} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment