I am trying to add custom layout to change my selected item text in my spinner. But I couldn't reach my layout file with R.layout.my_selected_item in my array adapter. It is saying "Unresolved reference: my_selected_item".
ArrayAdapter:
val sortedCurrencySymbolsList = listOf("BTC", "ETH", "XRP", "USDC", "BNB",
"DOGE", "LTC", "MATIC", "DYDX", "ADA").sorted()
ArrayAdapter(
requireContext(),
R.layout.my_selected_item,
sortedCurrencySymbolsList
) .also {
it.setDropDownViewResource(R.layout.simple_spinner_dropdown_item)
binding.spinnerCrypto.adapter = it
}
my_selected_item:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:textAlignment="inherit"/>
I tried clean/rebuild and invalidate caches restart but it didn't help. I imported "import com.menesdurak.virtualcrypto.R.layout.my_selected_item" and it didn't help too. I opened new project, tried to add new layout in there and it worked. But in my project, Android Studio don't let me do it. Somehow in my project it don't let me add my custom layout.
Thanks for your helps.
CodePudding user response:
Please Check your imports I think you are importing the wrong R package.