-2

Please i would like a detailed explanation on what an inner class does what happens in this specific instance. If i dont type out the inner in an inner class of recycleview. calling notifyDataSetChanged() throws an error like this

enter image description here

But if i type inner in front of the ViewHolder Class. The notifyDataSetChanged() error clears

enter image description here

samuel ochuba
  • 67
  • 1
  • 10

3 Answers3

0

A nested class marked as inner can access the members of its outer class. Here the class ViewHolder is nested in the class TimeAdapter. So it need to be marked as inner to access to the function "notifyDataSetChanged" of the class TimeAdapter

Vanilil
  • 71
  • 1
  • 6
0

kotlin inner classes have access to outer class that's why you can call notifyDataSetChanged() method of RecyclerViewAdapter. If you don't make it inner class it doesn't have access to outer class and you can't call outer class method.

Bek
  • 7,790
  • 4
  • 18
  • 31
0

Inner make the inner class access the outer class methods

Bek answered you

https://stackoverflow.com/a/65219384/8139353

but i have a simple note about notifyDataSetChanged()

you must avoid using it if you want to update a specific rows

you must use notifyItemChanged(layoutPosition) this function update only the row you updating

and if you had updated more than one row you can use notifyItemRangeChanged(layoutPosition, 5)// position and items count

there are many fuctions to use it in adapter like notifyItemRemoved(layoutPosition)

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mohammad Khair
  • 436
  • 6
  • 15