当前位置:首页 > Android > 正文内容

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

jsc10年前 (2016-04-06)Android3771

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中Parcelable接口用法

1. Parcelable接口Interface for classes whose instances can be written to and restored from a Parcel。 Classes implementing the Parcelable interface m...

实现应用程序只有在第一次启动时显示引导界面

第一次安装启动:启动页--->导航页-->主页面之后启动:启动页-->主页面实现的原理就是:在启动页面用做一个文件保存的状态,保存程序是不是第一次启动的状态。因为只是要保存一个状态,我们将这个程序是第一次打开就将他设为true,当他进入 主页面之后将他的状态未为false,因为都...

Android ImageView的scaleType属性与adjustViewBounds属性

Android ImageView的scaleType属性与adjustViewBounds属性

ImageView的scaleType的属性有好几种,分别是matrix(默认)、center、centerCrop、centerInside、fitCenter、fitEnd、fitStart、fitXY android:sca...

Fragment保持状态切换

Fragment保持状态切换

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

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

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

GridView中item高度自适应

item高度自适应public class MyAdapter extends BaseAdapter {         GridView mGv;&n...