要解决Android上的可搜索下拉菜单无法正常工作的问题,可以尝试以下解决方法:
示例代码:
AutoCompleteTextView autoCompleteTextView = findViewById(R.id.autoCompleteTextView);
ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, data);
autoCompleteTextView.setAdapter(adapter);
示例代码:
List data = new ArrayList<>();
data.add("Apple");
data.add("Banana");
data.add("Orange");
AutoCompleteTextView autoCompleteTextView = findViewById(R.id.autoCompleteTextView);
ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, data);
autoCompleteTextView.setAdapter(adapter);
示例代码:
AutoCompleteTextView autoCompleteTextView = findViewById(R.id.autoCompleteTextView);
ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, data);
autoCompleteTextView.setAdapter(adapter);
autoCompleteTextView.setThreshold(1);
autoCompleteTextView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
adapter.getFilter().filter(s);
}
@Override
public void afterTextChanged(Editable s) {
}
});
通过检查以上几个方面,可以确定是否有任何错误导致Android上的可搜索下拉菜单无法正常工作,并采取相应的解决方法。
上一篇:Android上的可搜索下拉菜单