In my Android project I have two layouts: num_info and num_info_pack. Both have views with id "circle". So I thought referencing those views by layout_name.circle would solve the problem:
val inetView = activity.layoutInflater.inflate(R.layout.num_info_pack, parent, false)
inetView.circle.setBackgroundResource(background)
But circle is underlined with red and it says:
Overload resolution ambiguity. All these functions match.
public val View.circle: View! defined in kotlinx.android.synthetic.main.num_info_pack.view
public val View.circle: RelativeLayout! defined in kotlinx.android.synthetic.main.num_info_inet_plus_pack.view
Why is it confused about which circle I'm talking about if I'm specifically saying inetView.circle?
In addition to the already very good answers, if you have the same IDs in multiple layouts in your project, it shouldn't matter which one you pick. Similar IDs, regardless of which layout it is defined, end up pointing to the same view. So, you can discard the other imports, leaving only the layout(s) that matters to you in the current activity/fragment/view
Hope that helps
The solution here is in the imports. You must be importing two layouts like
import kotlinx.android.synthetic.main.num_info_pack
and
import kotlinx.android.synthetic.main.num_info_inet_plus_pack
Remove one of them and keep one with the appropriate layout file that you want to import. It should work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With