Skip to content

Commit c4d2492

Browse files
committed
feat #9: replace the contents of a view
1 parent 0d0d4e0 commit c4d2492

File tree

1 file changed

+7
-2
lines changed
  • Affirmations/app/src/main/java/com/example/affirmations/adapter

1 file changed

+7
-2
lines changed

Affirmations/app/src/main/java/com/example/affirmations/adapter/ItemAdapter.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,24 @@ class ItemAdapter(private val context: Context, private val dataset: List<Affirm
1616
RecyclerView.Adapter<ItemAdapter.ItemViewHolder>() {
1717

1818
// creating view holder for ItemAdapter
19+
// provide a reference to the views for each data item
20+
// provide access to all the views for a data item in a view holder
1921
class ItemViewHolder(private val view: View) : RecyclerView.ViewHolder(view) {
2022
val textView: TextView = view.findViewById(R.id.item_title)
2123
}
2224

2325
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
24-
// create a new view
26+
// create a new views
2527
val adapterLayout =
2628
LayoutInflater.from(parent.context).inflate(R.layout.list_item, parent, false)
2729
return ItemViewHolder(adapterLayout)
2830
}
2931

3032
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
31-
TODO("Not yet implemented")
33+
// replace the contents of a view by right data set
34+
// find the right affirmation object from the data set based on position
35+
val item = dataset[position]
36+
holder.textView.text = context.resources.getString(item.stringResourceId)
3237
}
3338

3439
// return the size of the dataset

0 commit comments

Comments
 (0)