Java 在android中的微调器中设置默认值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9731618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting default values in spinner in android
提问by Muhammad Umar
I am using a spinner using following code
我正在使用以下代码使用微调器
private String `DEFAULT_CURRENCY_TYPE`;
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, currenciesDataSource.keys);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
paidIn.setAdapter(adapter);
I want to do something like that paidIn.setDefault(DEFAULT_CURRENCY_TYPE)
我想做这样的事情 paidIn.setDefault(DEFAULT_CURRENCY_TYPE)
Meaning whenever i create spinner it compare its values with my default values and then set it as first element. How can i do that?
这意味着每当我创建微调器时,它都会将其值与我的默认值进行比较,然后将其设置为第一个元素。我怎样才能做到这一点?
Best Regards
此致
采纳答案by hungr
try this:
尝试这个:
spinner.setSelection(adapter.getPosition(DEFAULT_CURRENCY_TYPE))
回答by Manju
I think you can use spinner.setSelection(position) may be the solution if i understood your question clearly
如果我清楚地理解你的问题,我认为你可以使用 spinner.setSelection(position) 可能是解决方案