0
0
Android Kotlinmobile~10 mins

Why dynamic lists display data efficiently in Android Kotlin - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a RecyclerView adapter class in Kotlin.

Android Kotlin
class MyAdapter(private val items: List<String>) : RecyclerView.[1]<MyAdapter.ViewHolder>() {
  // Adapter implementation
}
Drag options to blanks, or click blank then click option'
ARecyclerView.Adapter
BRecyclerView.ViewHolder
CViewHolder
DAdapter
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'RecyclerView.Adapter' duplicates the RecyclerView prefix, causing compilation errors.
Confusing ViewHolder with Adapter class.
2fill in blank
medium

Complete the code to inflate the item layout in onCreateViewHolder method.

Android Kotlin
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
  val view = LayoutInflater.from(parent.context).inflate([1], parent, false)
  return ViewHolder(view)
}
Drag options to blanks, or click blank then click option'
AR.id.item_view
BR.layout.item_view
CR.string.item_view
DR.drawable.item_view
Attempts:
3 left
💡 Hint
Common Mistakes
Using R.id or R.string instead of R.layout causes runtime errors.
Passing null instead of parent causes layout issues.
3fill in blank
hard

Fix the error in binding data to the TextView inside onBindViewHolder.

Android Kotlin
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
  holder.textView.[1] = items[position]
}
Drag options to blanks, or click blank then click option'
Atext
BgetText()
CsetText()
DtextView
Attempts:
3 left
💡 Hint
Common Mistakes
Using setText() like in Java causes syntax errors in Kotlin.
Using getText() tries to read text instead of setting it.
4fill in blank
hard

Fill both blanks to create a list that updates efficiently with RecyclerView.

Android Kotlin
val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
recyclerView.layoutManager = [1](this)
recyclerView.adapter = MyAdapter([2])
Drag options to blanks, or click blank then click option'
ALinearLayoutManager
BGridLayoutManager
ClistOf("Apple", "Banana", "Cherry")
DarrayListOf("Apple", "Banana", "Cherry")
Attempts:
3 left
💡 Hint
Common Mistakes
Using GridLayoutManager without understanding layout changes.
Using immutable listOf when data needs to change.
5fill in blank
hard

Fill all three blanks to implement ViewHolder class with a TextView reference.

Android Kotlin
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
  val [1]: TextView = itemView.findViewById([2])
  fun bind(text: String) {
    [3].text = text
  }
}
Drag options to blanks, or click blank then click option'
AtextView
BR.id.textView
CitemView
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causes errors.
Using itemView instead of R.id.textView in findViewById.