Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用整数数组获取布局_Java_Android_Xml - Fatal编程技术网

Java 使用整数数组获取布局

Java 使用整数数组获取布局,java,android,xml,Java,Android,Xml,我想使用java文件中的。然而,我得到的是0 res/values/worlds.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <integer-array name="world1"> <item>@layout/lvl_1</item> <item>@layout/lvl_1</item>

我想使用java文件中的。然而,我得到的是0

res/values/worlds.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer-array
        name="world1">
        <item>@layout/lvl_1</item>
        <item>@layout/lvl_1</item>
    </integer-array>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <array
        name="world1">
        <item>@layout/lvl_1</item>
        <item>@layout/lvl_1</item>
    </array>
</resources>
Java代码在我的Logcat上给了我一个0

<item>@layout/lvl_1</item>  
在代码集中布局为:

TypedArray layouts = getResources().obtainTypedArray(R.array.world1);
int layoutid=layouts.getResourceId(0, -1);
setContentView(layoutid);
layouts.recycle();
在代码集中布局为:

TypedArray layouts = getResources().obtainTypedArray(R.array.world1);
int layoutid=layouts.getResourceId(0, -1);
setContentView(layoutid);
layouts.recycle();

可能重复的可能重复的这个工作完美!请原谅,如果我可以补充的话,是否有任何方法可以将这个类型化数组存储到一个数组中?我想在检索到的版面ID上使用Collections.shuffle这非常有效!请原谅,如果我可以补充的话,是否有任何方法可以将这个类型化数组存储到一个数组中?我想在检索到的版面ID上使用Collections.shuffle