如何獲得AutoCompleteTextView
中的當前最佳建議?我有建議項目,我有一個文本更改偵聽器註冊。我也在同一個屏幕上有一個列表。當他們鍵入時,我想將列表滾動到當前的「最佳」建議。但我無法弄清楚如何訪問當前的建議,或至少是最重要的建議。我想我正在尋找類似:從「AutoCompleteTextView」獲取當前建議
autoCompleteTextView.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
String currentText = autoCompleteTextView.getText();
String bestGuess = autoCompleteTextView.getCurrentSuggestions()[0];
// ^^^ mewthod doesn't exist
doSomethingWithGuess(bestGuess);
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// do nothing
}
public void afterTextChanged(Editable s) {
// do nothing
}
});
很好的答案!比我下面的黑客好得多。 – 2010-10-26 07:17:28
非常感謝你。我正在嘗試幾天,想知道如何根據過濾項目的數量動態更改我的下拉菜單的高度,並且它似乎是在'afterTextChanged'事件之後過濾的。 dataSetObserver正是我需要的偵聽器,它使它工作 – Mike 2013-01-28 15:57:46
這是一個現貨! – 2013-09-03 07:30:45