Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.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
Android 在Spinner上,如何访问string.xml中提到的值_Android_Arrays_Xml - Fatal编程技术网

Android 在Spinner上,如何访问string.xml中提到的值

Android 在Spinner上,如何访问string.xml中提到的值,android,arrays,xml,Android,Arrays,Xml,如何从string.xml访问值 <string-array name="countries_array"> <item value="in">India</item> </string-array> 这使得印度非常容易,下面是一个例子: String[] countries= getResources().getStringArray(R.array.countries_array); String country= countrySe

如何从string.xml访问

<string-array name="countries_array">
    <item value="in">India</item>
</string-array>

这使得印度非常容易,下面是一个例子:

String[] countries= getResources().getStringArray(R.array.countries_array);
String country= countrySelector.getSelectedItem().toString();
或者,您可以根据用户选择作出响应:

public void onItemSelected(AdapterView<?> parent, View view, 
        int pos, long id) {
    // An item was selected. You can retrieve the selected item using
    String country = countries[pos];
}
public void未选中(AdapterView父视图、视图、,
内部位置,长id){
//已选择一个项目。您可以使用
字符串country=countries[pos];
}

为此创建一个字典。@t这将花费很多时间。它很长。我在上面的mannersorry中有数据,然后创建另一个类似于的数组并找到匹配项。India是xml数据中的值,您可以输入和India,它将不起作用@meda你不明白我的意思,我想在spinner中展示
印度
,因为我只想在中接收

public void onItemSelected(AdapterView<?> parent, View view, 
        int pos, long id) {
    // An item was selected. You can retrieve the selected item using
    String country = countries[pos];
}