OnClick与android:focusableInTouchMode="true"
16lz
2022-05-02
也许这是一个老问题,但是遇到了。所以将自己找的解决办法写下来。
程序中有一个button,它设置了android:focusableInTouchMode=“true”,并且也设置了按键onClick方法。那么第一次点击的时候,它将取得焦点,而第二次点击的时候,才执行onClick方法。我所需要的效果是,同时在第一次点击的时候了得焦点,并且执行onClick方法。
button.setOnTouchListener(new onTouchListenerImpl()); class onTouchListenerImpl implements OnTouchListener { @Override public boolean onTouch(View v, MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_UP) { v.performClick(); } return false; } };
更多相关文章
- Android中经常用到的方法--SDcard下文件的操作
- android之Fragment(官网资料翻译)
- Android中解析XML
- Android中解析XML
- android zxing 4.7.1横屏改竖屏 screenOrientation landscape to
- Android(安卓)Touch事件分发响应机制
- Android中软键盘弹出时底部布局上移问题
- 浅谈Java中Collections.sort对List排序的两种方法
- Python list sort方法的具体使用