Merge "Fix NPE in AutoCompleteTextView to tame the monkeys. Bug #2522599"

This commit is contained in:
Romain Guy
2010-03-17 11:10:07 -07:00
committed by Android (Google) Code Review

View File

@@ -660,14 +660,20 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
final boolean below = !mPopup.isAboveAnchor();
final ListAdapter adapter = mDropDownList.getAdapter();
final boolean allEnabled = adapter.areAllItemsEnabled();
final int firstItem = allEnabled ? 0 :
mDropDownList.lookForSelectablePosition(0, true);
final int lastItem = allEnabled ? adapter.getCount() - 1 :
mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false);
final ListAdapter adapter = mAdapter;
boolean allEnabled;
int firstItem = Integer.MAX_VALUE;
int lastItem = Integer.MIN_VALUE;
if (adapter != null) {
allEnabled = adapter.areAllItemsEnabled();
firstItem = allEnabled ? 0 :
mDropDownList.lookForSelectablePosition(0, true);
lastItem = allEnabled ? adapter.getCount() - 1 :
mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false);
}
if ((below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex <= firstItem) ||
(!below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN && curIndex >= lastItem)) {
// When the selection is at the top, we block the key