Skip to content

Instantly share code, notes, and snippets.

@vxhviet
Created March 5, 2019 04:30
Show Gist options
  • Save vxhviet/20ce5bf04661b3e9289c8a6a08f55b23 to your computer and use it in GitHub Desktop.
Save vxhviet/20ce5bf04661b3e9289c8a6a08f55b23 to your computer and use it in GitHub Desktop.

Reference duplicated View's IDs in with Kotlin synthetic

SOURCE, EXTRA

Instead of importing

kotlinx.android.synthetic.main.layout.day_row.*

you can import

kotlinx.android.synthetic.main.layout.day_row.view.*

(Notice the additional .view at the end).

This will import the views not as properties on the Activity/Fragment level, but instead as extension properties for View. That way, you can do it the way you want, assuming that day1 and day2 contain the views you want:

day1.dayName.text = "xxx"
day2.dayName.text = "sss"

See Extra for other cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment