android - 从资源字符串数组创建 ArrayList<String>

标签 android kotlin

我已经声明了 ArrayList 之类的,

var otherSeriesList = ArrayList<String>()

并尝试通过关注从资源中获取数据,

otherSeriesList = ArrayList<String>(Arrays.asList(resources.getStringArray(R.array.get_other_series)))

但我遇到了错误。请看图—— enter image description here

我应该如何从资源字符串数组创建 ArrayList?

最佳答案

简单的这样做-

otherSeriesList = ArrayList<String>(Arrays.asList(*resources.getStringArray(R.array.get_other_series)))

* 将数组作为可变参数传递

关于android - 从资源字符串数组创建 ArrayList<String>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48207631/

相关文章:

android - 空对象引用上的 FragmentActivity.getSupportFragmentManager()'

android - 在抽象类中获取应用上下文

机器人 : how does the OS chose a component implementation when multiple implementation respond to the same intent?

android - 如果它不适合 TextView 中的 1 行,如何在字符串末尾显示 ...?

java - 在java中使加号成为一个字符串

gradle - Kotlin Quasar 示例不起作用

kotlin - 为什么 Kotlin 反编译器生成 null.INSTANCE

android - 使用 setGraph() 以编程方式设置图形会导致应用程序无法在进程终止后恢复堆栈(Jetpack 导航)

android - Mapbox SymbolLayer 隐藏标记

kotlin - 空指针异常 : Testing DAO class that uses Ebean with Mockito and JUnit, Kotlin