Android 在Spinner上,如何访问string.xml中提到的值
如何从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-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];
}