如何通过里面的文字设置微调选择 [英] how to set spinner selection by text inside it

查看:160
本文介绍了如何通过里面的文字设置微调选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我preparing中,我必须使用相同的页面添加详细信息和编辑信息的形式。虽然增加的细节,所有的字段为空,并微调选择将被设置为不选择。
现在,我想设置对此我打算从previous活动通过该项目的微调选择。如何实现这一目标?
由于微调没有任何方法类似, setSelection(字符串字符串);
或有任何其他的方式,我能实现这个机制...

I preparing a form in which i have to use same page for Adding details and Editing details. While adding details all fields will be blank and spinner selection will be set to "no selection". Now i want to set the spinner selection of the item which i am going to pass from the previous activity. How to achieve this ?? As spinner does not have any method something like, setSelection(String string); Or is there any other way, i can achieve this mechanism...

会有人帮我...

推荐答案

我现在不多久,这可能被使用,但我们可以通过它里面的文字设置Spinner的选择。
微调有方法的 setSelection(INT位置);

I dont now how frequently this might be used but we can set selection of the spinner by text inside it. Spinner has the method setSelection(int position);.

现在,我们需要通过文字,我们可以从我们使用绑定到适配器array_list获得位置的参数,由 getIndexOf(Object对象)和对象应该是被声明例如,如果的ArrayList 的类型为String 的ArrayList 的类型,对象的传递给 getIndexOf(Object对象)应该是String类型的。

Now in the parameter we need to pass position of the text, which we can get from the array_list we use to bind to adapter, by getIndexOf(Object object) and object should be of the type of ArrayList that is declared For example, if ArrayList is of type String, the object to be passed to getIndexOf(Object object) should be of type String.

最后,设置选择如下:

spinner.setSelection ( spinner_array_list.indexOf(string) );

这篇关于如何通过里面的文字设置微调选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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