Android的微调OnItemSelectedListener不能准确地工作 [英] Android Spinner OnItemSelectedListener not working accurately

查看:192
本文介绍了Android的微调OnItemSelectedListener不能准确地工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个微调并启动监听器:

I have created a Spinner and activated the listener:

customerListSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
    public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
        // I do some work here
    }
    public void onNothingSelected(AdapterView<?> arg0) {
        isInitRadioGroup = false;
    }
 );

最初我已经添加了微调三个值:搜索,员工,公司。
如果用户选择搜索,一个新ListActivity示出和所选择的值被加入到上述微调作为结果。结果
这样,我在表演的微调项目的选择有所行动。现在,当第一次显示在屏幕上,默认情况下,搜索所示。到触发ListActivity的处理中,用户有选择一次搜索。这次,ItemSelected回调不叫。我的意思是说,如果一个微调值已被选中,然后在相同值的选择一遍,不会触发监听器。

I have added three values in the Spinner initially: "Search", "Employee", "Company". If the user selects "Search", a new ListActivity is shown and the selected value is added to the above Spinner as a result.
Like this, I am performing some action on the selection of the spinner Item. Now, When the screen is shown at first time, by default "Search" is shown. To trigger the processing of the ListActivity, the user has to select the "Search" again. This time, on ItemSelected callback is not called. I mean to say, if a value in Spinner is already selected, then on the selection of the same value again, does not trigger the listener.

鉴于:
当第一次显示在屏幕上,默认情况下,搜索所示。用户选择(onItemSelected称为作为previous选择的值大于由用户选择的值不同的该处理完成后,)的值雇员。然后,用户选择了值搜索。这一次的onItemSelected方法被调用,并成功地增加了一个新值微调。

Whereas: When the screen is shown at first time, by default "Search" is shown. The user selects the value "Employee" (processing for this is done, onItemSelected is called as the previous selected value is different than the value selected by the user). The user then selects the value "Search". This time the onItemSelected method is called and successfully adds a new value to the Spinner.

这是Android系统中的错误。我已签有我的code没有错误。

This is a bug of Android. I have checked there is no error in my code.

推荐答案

尝试使用微调如下

Spinner genspin=(Spinner)findViewById(R.id.gender);

ArrayAdapter<String> genadap=new ArrayAdapter(this,R.layout.spinneritems,String_array);
genadap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
genspin.setAdapter(genadap);
genspin.setOnItemSelectedListener(this);

那么你可以得到所选择的值

then you can get the selected value as

genspin.getSelectedItem().toString()

这篇关于Android的微调OnItemSelectedListener不能准确地工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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