Merge "Avoid NPE when getPositionForView() is called on detached view" into mnc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9513785715
@@ -612,7 +612,7 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
|
|||||||
View listItem = view;
|
View listItem = view;
|
||||||
try {
|
try {
|
||||||
View v;
|
View v;
|
||||||
while (!(v = (View) listItem.getParent()).equals(this)) {
|
while ((v = (View) listItem.getParent()) != null && !v.equals(this)) {
|
||||||
listItem = v;
|
listItem = v;
|
||||||
}
|
}
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
@@ -620,6 +620,7 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
|
|||||||
return INVALID_POSITION;
|
return INVALID_POSITION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (listItem != null) {
|
||||||
// Search the children for the list item
|
// Search the children for the list item
|
||||||
final int childCount = getChildCount();
|
final int childCount = getChildCount();
|
||||||
for (int i = 0; i < childCount; i++) {
|
for (int i = 0; i < childCount; i++) {
|
||||||
@@ -627,6 +628,7 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
|
|||||||
return mFirstPosition + i;
|
return mFirstPosition + i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Child not found!
|
// Child not found!
|
||||||
return INVALID_POSITION;
|
return INVALID_POSITION;
|
||||||
|
|||||||
Reference in New Issue
Block a user