I’m migrating from kotlinx.android.synthetic
to ViewBindings
.
I have two layouts(for phones and tablets) with the same set of ids:
lateinit var binding: ViewBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (AppData.instance.isTablet)
binding=ActivityGameTabletBinding.inflate(layoutInflater)
else
binding=ActivityGamePhoneBinding.inflate(layoutInflater)
setContentView(binding.root)
val btn=binding.menuBtn //no such property
}
...
}
The problem is binding
contains only one property which is root
.
Thus I’m forced to fallback to old getViewById
.
Is there way to have viewBinding features for different layouts?