如何获取类型数组中项目的索引?

问题描述

我想将可绘制对象存储在这样的资源数组中:

    <integer-array name="sensor_icon_values">
        <item>@drawable/sensor_brightness</item>
        <item>@drawable/sensor_temperature</item>
        <item>@drawable/sensor_humidity</item>
        <item>@drawable/sensor_carbon_dioxide</item>
        <item>@drawable/sensor_voltage</item>
    </integer-array>

如何在 kotlin 中获取某个项目的索引? 假设我想获取资源 ID 为 2131230874 的元素的索引。

我知道我可能必须使用这样的类型化数组:

val sensorIcons = resources.obtainTypedArray(R.array.sensor_icon_values)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)