简体   繁体   English

我无法使用 R.layout.(file_name) 在我的适配器中访问我的布局文件

[英]I can't reach my layout file in my adapter with R.layout.(file_name)

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.但是我无法在我的阵列适配器中使用 R.layout.my_selected_item 访问我的布局文件。 It is saying "Unresolved reference: my_selected_item".它说“未解决的参考:my_selected_item”。

You can see error here:您可以在此处看到错误:

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:我的_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.我导入了“import com.menesdurak.virtualcrypto.R.layout.my_selected_item”,但也没有用。 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.但是在我的项目中,Android工作室不让我做。 Somehow in my project it don't let me add my custom layout.在我的项目中,它以某种方式不允许我添加自定义布局。

Thanks for your helps.感谢您的帮助。

Please Check your imports I think you are importing the wrong R package.请检查您的进口我认为您进口错误R package。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM