Skip to content

Instantly share code, notes, and snippets.

@ixiyang
Created July 28, 2014 00:53
Show Gist options
  • Save ixiyang/5e529c0ee40cfcd493f4 to your computer and use it in GitHub Desktop.
Save ixiyang/5e529c0ee40cfcd493f4 to your computer and use it in GitHub Desktop.
find the child view that was touched in a listview
Rect rect = new Rect();
int childCount = mListView.getChildCount();
int[] listViewCoords = new int[2];
mListView.getLocationOnScreen(listViewCoords);
System.err.println("listViewCoords[0]====>"+listViewCoords[0]);
System.err.println("listViewCoords[1]====>"+listViewCoords[1]);
int x = (int) motionEvent.getRawX() - listViewCoords[0];
int y = (int) motionEvent.getRawY() - listViewCoords[1];
View child;
for (int i = 0; i < childCount; i++) {
child = mListView.getChildAt(i);
child.getHitRect(rect);
if (rect.contains(x, y)) {
mDownView = child;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment