当前位置:首页 > Android

Sipnner点击相同Item不响应的解决方法

jsc10年前 (2016-04-06)Android3821

Spinner,两次点击同一个item的时候,第二次会不响应OnItemSelect事件。

解决方法:

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) 
{
    //do what you want
    ......
    //after you do
    /*here items is the adapter's items*/
    int size = items.size();
    Spinner spinner = (Spinner)arg1.getParent();
    spinner.setSelection(size); 
}

也就是说:只要在选择处理完成之后,主动设置选中的item的index >= adapter的个数就行了。

下次点击相同的item的时候,就会响应了。

当然,这里有个问题:就是选择之后显示的文字不对。这里你需要保存一下你当前选择的文字的。

或者重写一个adapter,重写里面的getView方法。


扫描二维码推送至手机访问。

版权声明:本文由微小站发布,如需转载请注明出处。

本文链接:https://jsc0.com/post/68.html

分享给朋友:

“Sipnner点击相同Item不响应的解决方法” 的相关文章

Android Location在GPS中的应用(一)

Android Location在GPS中的应用(一)

新建AndroidProject,注意选择Google APIs:  打开AndroidManifest.xml,在其中加入GPS使用权限:......…

修改keystore密码别名等

修改keystore密码别名等

之前在测试Eclipse ADT的Custom debug ˂a target="_blank" title="View all posts in keystore" hr…

Fragment保持状态切换

Fragment保持状态切换

在使用Activity管理多个Fragment时,每次切换Fragment使用的是replace,结果导致出现xxx is not currently in the FragmentManager异常挂掉网上说使用replace切换会使被切换的Fragment给替换掉,从而被被切换的Fra…

Android中的消息通知(NotificationManager和Notification)

下面来谈谈notification,这个notification一般用在电话,短信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提 示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这个快讯。已添加的Notification.Builder,使其更容易构建通知。 notifica…

采用SharedPreferences保存用户偏好设置参数

采用SharedPreferences保存用户偏好设置参数-------------------------------------------------1.eclipse就是通过xml来保存用户的偏好设置-->window-->perfences-------------------…

采用SharedPreferences保存用户偏好设置参数和读取设置参数

采用SharedPreferences保存用户偏好设置参数和读取设置参数

Android SDK支持那些文件存储技术? 1. 使用SharedPreferences保存key-value类型的数据 ˂span style="font…