code: 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;
      }
docs: 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.
  
  @param view an adapter item, or a descendant of an adapter item. This must be visible in this
  AdapterView at the time of the call.
  @return the position within the adapter's data set of the view, or {@link #INVALID_POSITION}
  if the view does not correspond to a list item (or it is not currently visible).