am 95137857: Merge "Avoid NPE when getPositionForView() is called on detached view" into mnc-dev

* commit '9513785715e2325ee3a3269fbfe7b1f4409eff5c':
  Avoid NPE when getPositionForView() is called on detached view
This commit is contained in:
Alan Viverette
2015-08-26 20:45:26 +00:00
committed by Android Git Automerger

View File

@@ -612,7 +612,7 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
View listItem = view;
try {
View v;
while (!(v = (View) listItem.getParent()).equals(this)) {
while ((v = (View) listItem.getParent()) != null && !v.equals(this)) {
listItem = v;
}
} catch (ClassCastException e) {
@@ -620,11 +620,13 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
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;
if (listItem != null) {
// 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;
}
}
}