When debugging a problem with the search dialog drop-down sometimes not showing up, I saw that the mAttachCount variable in AutoCompleteTextView could get a negative value because onDetachedFromWindow() was called multiple times. This lead to the drop-down not being displayed on filtering. Instead of the private attach count in ACTV, this change uses View.getWindowVisibility().