diff options
| author | Romain Guy <romainguy@android.com> | 2010-03-17 10:31:15 -0700 |
|---|---|---|
| committer | Romain Guy <romainguy@android.com> | 2010-03-17 10:39:04 -0700 |
| commit | 4f43ae09d2cb0cce2b9e794f1b80f7198333c94b (patch) | |
| tree | c43c4fcfd4efe8cbd00f9383cbc9496f7a10f885 /core/java/android/widget/AutoCompleteTextView.java | |
| parent | 4889fb75d463278241d5174baac05a41dbef25a8 (diff) | |
Stupid AutoCompleteTextView.
Bug #2522538
Fixes problems that occur in the Email application. If the adapter is initially empty,
the code in the data set observer to update the popup would not show the popup. This
change makes sure the popup will be shown if the adapter was initially empty and the
user has typed enough characters in the input field.
Change-Id: I44a0e4fab18a642763816a974b8c1886d8e52869
Diffstat (limited to 'core/java/android/widget/AutoCompleteTextView.java')
| -rw-r--r-- | core/java/android/widget/AutoCompleteTextView.java | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java index 9537ba0fa07e..54829587acfd 100644 --- a/core/java/android/widget/AutoCompleteTextView.java +++ b/core/java/android/widget/AutoCompleteTextView.java @@ -985,6 +985,11 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe /** {@inheritDoc} */ public void onFilterComplete(int count) { + updateDropDownForFilter(count); + + } + + private void updateDropDownForFilter(int count) { // Not attached to window, don't update drop-down if (getWindowVisibility() == View.GONE) return; @@ -1214,18 +1219,30 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe ViewGroup dropDownView; int otherHeights = 0; - if (mAdapter != null) { + final ListAdapter adapter = mAdapter; + if (adapter != null) { InputMethodManager imm = InputMethodManager.peekInstance(); if (imm != null) { - int N = mAdapter.getCount(); - if (N > 20) N = 20; - CompletionInfo[] completions = new CompletionInfo[N]; - for (int i = 0; i < N; i++) { - Object item = mAdapter.getItem(i); - long id = mAdapter.getItemId(i); - completions[i] = new CompletionInfo(id, i, - convertSelectionToString(item)); + final int count = Math.min(adapter.getCount(), 20); + CompletionInfo[] completions = new CompletionInfo[count]; + int realCount = 0; + + for (int i = 0; i < count; i++) { + if (adapter.isEnabled(i)) { + realCount++; + Object item = adapter.getItem(i); + long id = adapter.getItemId(i); + completions[i] = new CompletionInfo(id, i, + convertSelectionToString(item)); + } } + + if (realCount != count) { + CompletionInfo[] tmp = new CompletionInfo[realCount]; + System.arraycopy(completions, 0, tmp, 0, realCount); + completions = tmp; + } + imm.displayCompletions(this, completions); } } @@ -1253,7 +1270,7 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe mDropDownList = new DropDownListView(context); mDropDownList.setSelector(mDropDownListHighlight); - mDropDownList.setAdapter(mAdapter); + mDropDownList.setAdapter(adapter); mDropDownList.setVerticalFadingEdgeEnabled(true); mDropDownList.setOnItemClickListener(mDropDownItemClickListener); mDropDownList.setFocusable(true); @@ -1599,6 +1616,16 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe if (isPopupShowing()) { // This will resize the popup to fit the new adapter's content showDropDown(); + } else if (mAdapter != null) { + // If the popup is not showing already, showing it will cause + // the list of data set observers attached to the adapter to + // change. We can't do it from here, because we are in the middle + // of iterating throught he list of observers. + post(new Runnable() { + public void run() { + updateDropDownForFilter(mAdapter.getCount()); + } + }); } } |
