public int getPositionForView ( View view ) { View listItem = view ; try { View v ; while ( ! ( v = ( View ) listItem . getParent ( ) ) . equals ( this ) ) { listItem = v ; } } catch ( ClassCastException e ) { // We made it up to the window without find this list view return INVALID_POSITION ; } // Search the children for the list item final int childCount = getChildCount ( ) ; for ( int i = 0 ; i < childCount ; i ++ ) { if ( getChildAt ( i ) . equals ( listItem ) ) { return mFirstPosition + i ; } } // Child not found! return INVALID_POSITION ; }
Get the position within the adapter s data set for the view where view is a an adapter item or a descendant of an adapter item .