setOnTouchListener报警告
警告详细说明为:
Custom view `view` has setOnTouchListener called on it but does not override performClick less... (Ctrl+F1)
If a View that overrides onTouchEvent or uses an OnTouchListener does not also implement performClick and call it when clicks are detected, the View may not handle accessibility actions properly. Logic handling the click actions should ideally be placed in View#performClick as some accessibility services invoke performClick when a click action should occur.Issue id: ClickableViewAccessibility
【setOnTouchListener报警告】翻译一下大概意思就是:有可能会和点击事件发生冲突.
会出现问题的情况为:
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {}
});
在onTouch中返回ture,同时又添加了onClick监听,这时onClick就不会执行了,事件被onTouch消化掉了.来查看一下执行顺序就知道了,onTouchEvent=>performClick=>onClick,所以在onTouch返回ture时,同时又添加了onClick监听,正确的处理方法应该是在onTouch中适当的地方执行performClick方法,来触发onClick.
弄懂了原因以后可以添加一个注解就解决了
@SuppressLint("ClickableViewAccessibility")
推荐阅读
- 参保人员因患病来不及到指定的医疗机构就医,能否报销医疗费用()
- 【1057快报】深入机关,走下田间,交通普法,共创文明
- 调取接口时报404错误(ID:16)
- 2019年第22周报
- 东望志愿者的精神
- 接口|axios接口报错-参数类型错误解决
- 深夜碎碎念,权当解压
- Filecoin挖矿投资报告
- 大班一日保教工作汇报
- c#常用网址记录