更改字符串数组中的strings.xml到ArrayList中 [英] Change String-Array in Strings.xml to ArrayList

查看:122
本文介绍了更改字符串数组中的strings.xml到ArrayList中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序。我需要将一个字符串数组转换成一个ArrayList。我已经在这读了,一切都在您添加值到Java文件中的数组的情况下。我宣布了字符串数组中的strings.xml文件。我的字符串数组是在这里:

I'm developing an Android app. I need to convert a string array into an ArrayList. I've read up on this, and all have cases where you add the values to the array in the java file. I have declared the string-array in the strings.xml file. My string-array is here:

<string-array name="Lines">
    <item>Red Line</item>
    <item>Blue Line</item>
    <item>Orange Line</item>
    <item>Green Line</item>
    <item>Brown Line</item>
    <item>Purple Line</item>
    <item>Pink Line</item>
    <item>Yellow Line</item>
</string-array>

我需要线转换成ArrayList中。如果我用这个

I need to convert Lines into ArrayList. If I use this

List<String> Lines = new ArrayList<String>();

宣布ArrayList中,如何可以找到ID的数组列表,并存储为线?

to declare the ArrayList, how can find the array list by ID, and store that as Lines?

推荐答案

试试这个;

List<String> Lines = Arrays.asList(getResources().getStringArray(R.array.Lines));

这篇关于更改字符串数组中的strings.xml到ArrayList中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆