我将此代码用于 AutoCompleteTextView - 因此当您删除最后一个字符以显示列表时。但 mAutoCompleteTextView.showDropDown(); 无效。
mAutoCompleteTextView.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) {
}
@Override
public void afterTextChanged(Editable s) {
if (s.toString().equals("")) {
mAutoCompleteTextView.showDropDown();
}
}
});
答案 0 :(得分:2)
初始化小部件时,我记得类字段中的适配器。 用它来设置适配器
mAdapter = (ArrayAdapter<String>)actv.getAdapter(); // mAdapter is a class field
actv.setText("Tim Hortons");
actv.setSelection(0, actv.getText().length());
actv.setAdapter((ArrayAdapter<String>)null); // turn off the adapter
actv.requestFocus();
Handler handler = new Handler() {
public void handleMessage(Message msg) {
((AutoCompleteTextView)msg.obj).setAdapter(mAdapter);
};
Message msg = mHandler.obtainMessage();
msg.obj = actv;
handler.sendMessageDelayed(msg, 200);
希望这会对你有所帮助