Android Kotlin: Overload Resolution Ambiguity
July 24, 2020This happends when you define the same view id in two different layout, and you try to import both layout.
Layout
Notice the following layout shared the same view id of imageDraweeView
and selectionImageView
.
res/layout/batch_item_image.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tool="http://schemas.android.com/tools"
xmlns:fresco="http://schemas.android.com/apk/res-auto">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/imageDraweeView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
fresco:viewAspectRatio="1"
fresco:placeholderImage="@drawable/placeholder_100"
/>
<ImageView
android:id="@+id/selectionImageView"
android:layout_gravity="right|top"
android:layout_margin="8dp"
android:src="@drawable/ic_baseline_radio_button_unchecked_24"
android:tint="@android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
</FrameLayout>
res/layout/batch_item_image_with_text.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tool="http://schemas.android.com/tools"
android:orientation="horizontal"
xmlns:fresco="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/imageDraweeView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
fresco:viewAspectRatio="1"
fresco:placeholderImage="@drawable/placeholder_100"
/>
<ImageView
android:id="@+id/selectionImageView"
android:layout_gravity="right|top"
android:layout_margin="8dp"
android:src="@drawable/ic_baseline_radio_button_unchecked_24"
android:tint="@android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
</FrameLayout>
<TextView
android:id="@+id/imageTextView"
android:padding="16dp"
tool:text="Hello World"
android:layout_weight="2"
android:layout_width="0dp"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
android:layout_height="wrap_content" />
</LinearLayout>
Solution 1: use Different View Id
For res/layout/batch_item_image.xml
, define imageDraweeView
and selectionImageView
as per current.
For res/layout/batch_item_image_with_text.xml
, define withTextImageDraweeView
and withTextSelectionImageView
instead.
Solution 2: explicit import
Use explicit kotlin synthetic import.
import kotlinx.android.synthetic.main.batch_item_image.selectionImageView // explicit import to solve overload resolution ambiguity
import kotlinx.android.synthetic.main.batch_item_image.imageDraweeView // explicit import to solve overload resolution ambiguity
import kotlinx.android.synthetic.main.batch_item_image.*
import kotlinx.android.synthetic.main.batch_item_image_with_text.*
- algo-trading
- algolia
- analytics
- android
- android-ktx
- android-permission
- android-studio
- apps-script
- bash
- binance
- bootstrap
- bootstrapvue
- chartjs
- chrome
- cloud-functions
- coding-interview
- contentresolver
- coroutines
- crashlytics
- crypto
- css
- dagger2
- datastore
- datetime
- docker
- eslint
- firebase
- firebase-auth
- firebase-hosting
- firestore
- firestore-security-rules
- flask
- fontawesome
- fresco
- git
- github
- glide
- godot
- google-app-engine
- google-cloud-storage
- google-colab
- google-drive
- google-maps
- google-places
- google-play
- google-sheets
- gradle
- html
- hugo
- inkscape
- java
- java-time
- javascript
- jetpack-compose
- jetson-nano
- kotlin
- kotlin-serialization
- layout
- lets-encrypt
- lifecycle
- linux
- logging
- lubuntu
- markdown
- mate
- material-design
- matplotlib
- md5
- mongodb
- moshi
- mplfinance
- mysql
- navigation
- nginx
- nodejs
- npm
- nuxtjs
- nvm
- pandas
- payment
- pip
- pwa
- pyenv
- python
- recylerview
- regex
- room
- rxjava
- scoped-storage
- selenium
- social-media
- ssh
- ssl
- static-site-generator
- static-website-hosting
- sublime-text
- ubuntu
- unit-test
- uwsgi
- viewmodel
- viewpager2
- virtualbox
- vue-chartjs
- vue-cli
- vue-router
- vuejs
- vuelidate
- vuepress
- web-development
- web-hosting
- webpack
- windows
- workmanager
- wsl
- yarn