在日常开发中遇到这样一个问题,创建一个ListView,通过蓝牙搜索设备,向Adapter中添加设备,通过ListView进行设备展示。可是在蓝牙搜索过程中发现了·想要的设备名字,点击Adapter无任何响应,困扰了许久,最终发现是因为Adapter刷新过快导致ListView点击事件被屏蔽了。
来一起先看一下源码AbsListView的onTouchDown事件
private void onTouchDown(MotionEvent ev) {
mHasPerformedLongPress = false;
mActivePointerId = ev.getPointerId(0);
hideSelector();
if (mTouchMode == TOUCH_MODE_OVERFLING) {
// Stopped the fling. It is a scroll.
if (mFlingRunnable != null) {
mFlingRunnable.endFling();
}
if (mPositionScroller != null) {
mPositionScroller.stop();
}
mTouchMode = TOUCH_MODE_OVERSCROLL;
mMotionX = (int) ev.getX();
mMotionY = (int) ev.getY();
mLastY = mMotionY;
mMotionCorrection = 0;
mDirection = 0;
stopEdgeGlowRecede(ev.getX());
} else