setSelection不起作用的原因和解决办法

本文探讨了在Android中ListView使用setSelection(int position)时出现的失效情况。当设备处于touch mode时,setSelection不会改变选中状态,原因是Android在触摸模式下不显示焦点。同时,介绍了Android的Touch Mode概念,以及如何通过isInTouchMode判断当前模式。特殊情况如EditText即使在touch mode也能获取焦点,可通过setFocusableInTouchMode进行处理。
摘要由CSDN通过智能技术生成

打开一个listview的时候能够自动设置显示的位置, setSelection(int pos)可以设置显示的位置。

但是使用的时候大家会发现有时候起作用,有时候不起。

原因:

public void setSelection (int position)
Added in API level 1

Sets the currently selected item. If in touch mode, the item will not be selected but it will still be positioned appropriately. If the specified selection position is less than 0, then the item at position 0 will be selected.

touch mode的时候不起作用
touch mode指啥:从英文单词上来说,就是在触摸状态,下面一段具体的解释

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值