I'm new to Kotlin. Among other very interesting things, I've found the Android extensions which, according to the documentation, should let me use activities' views without the need of findViewById
.
Actually it works very well by adding just this line in my imports:
import kotlinx.android.synthetic.main.<layout>.*
The problem is when two different layouts contain a widget with the same id (i.e. the same name for the synthetic property),
e.g. two different TextView
s with the id txtTitle
. Say the first one is on an activity and the second one belongs to the layout used inside of an adapter.
When I try to call a method on the first TextView (the activity's one) I can't see the expected result, as if the call would be done on another view. As confirmation of this, when I call txtTitle.parent
, I see the parent and the siblings of the other txtTitle
rather than the ones expected.
Am I doing something wrong? The only ways I've found to bypass this issue is to use different names in all my layouts or continue to use findViewById
, but it would be a pity to waste this language feature...