微调串项值的get(不串名称)的Android [英] Spinner String item value get (not string name) android
本文介绍了微调串项值的get(不串名称)的Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在strings.xml中使用
I use in strings.xml
<string-array name="country_arrays">
<item value="0">ValueName0</item>
<item value="1">ValueName1</item>
<item value="2">ValueName2</item>
<item value="3">ValueName3</item>
<item value="4">ValueName4</item>
</string-array>
和我用在Java中code。对于获得选择期权价值
And i use in Java Code For Get Select Option Value
将String.valueOf(option.getSelectedItem())
Toast.makeText(AvpMain.this,
"Loading Wait : " + "\n Search : "+ sbox1 +
"\n("+ String.valueOf(option.getSelectedItem())+") Result",
Toast.LENGTH_SHORT).show();
如果用户选择ValueName3那么结果表明ValueName3 但我想显示值不VALUENAME
If User select ValueName3 then result show ValueName3 But I Want Show value not valuename
如。如果用户选择ValueName2那么结果显示:2
eg. if user select ValueName2 then result show:2
推荐答案
试试这个办法,希望这将帮助你解决你的问题。
的strings.xml
<array name="country_arrays">
<item>ValueName0</item>
<item>ValueName1</item>
<item>ValueName2</item>
<item>ValueName3</item>
<item>ValueName4</item>
</array>
<array name="country_value_arrays">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</array>
private ArrayList<String> countryList;
private ArrayList<String> countryValueList;
countryList = new ArrayList<String>(Arrays.asList(getResources().getStringArray(R.array.country_arrays)));
countryValueList = new ArrayList<String>(Arrays.asList(getResources().getStringArray(R.array.country_value_arrays)));
option.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(AvpMain.this,"Loading Wait : " + "\n Search : "+ sbox1 + "\n("+countryValueList.get(position)+") Result",Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
或
Toast.makeText(AvpMain.this,"Loading Wait : " + "\n Search : "+ sbox1 + "\n("+option.getSelectedItem().toString().charAt(option.getSelectedItem().toString().length())+") Result",Toast.LENGTH_SHORT).show();
这篇关于微调串项值的get(不串名称)的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文