java - 如何将资源数组和普通数组绑定(bind)到一个数组中?

标签 java android arrays android-resources

我认为这会将资源中的两个数组绑定(bind)到一个数组中:

Resource res=getResources();

final int[] one_array=res.getIntArray(R.array.first_array) + res.getIntArray(R.array.second_array);

但是变量数组不能像下面这样声明:

The operator + is undefined for the argument type(s) int[], int[]

我还想将资源中的两个数组+一个数组绑定(bind)到一个数组中。在我看来,应该是:

Resource res=getResource();

final int[] one_array={ 1,2,3,4,5,res.getIntArray(R.array.first_array),res.getIntArray(R.array.second_array) };

但是变量数组不能像下面这样声明:

Multiple markers at this line
    - Type mismatch: cannot convert from 
     int[] to int

如何实现通过绑定(bind)资源和普通数组中的两个数组来声明一个数组? 是否有其他/替代方法/解决方案来绑定(bind)数组?

最佳答案

尝试ArrayUtils.addAll

final int[] one_array = ArrayUtils.addAll(res.getIntArray(R.array.first_array), res.getIntArray(R.array.second_array);

+ 运算符将连接两个字符串。

关于java - 如何将资源数组和普通数组绑定(bind)到一个数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18524689/

相关文章:

java - xml 布局错误 :The following classes could not be found: - android. support.v4.view.Viewpager

Javascript 2D 数组问题更改特定元素更改列

Java - 将数据从txt文件传输到数组中

java - 字符串到 int 或 int 到字符串 : which is faster?

java - 无状态 bean 的依赖注入(inject)(@Inject 和 @PersistenceContext)失败

android - 如何更改 Android 模拟器中的制造商属性?

android - 如何设置正常的按钮颜色?

Android:父 View 组 ontouch 被忽略以支持 subview onclick

javascript - 对于来自 Node.js 数组的每个请求

java - 使用 docx4j 创建具有多个 header 的 docx