Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 不要在AutoCompleteTextView中打开下拉列表_Android_Autocomplete - Fatal编程技术网

Android 不要在AutoCompleteTextView中打开下拉列表

Android 不要在AutoCompleteTextView中打开下拉列表,android,autocomplete,Android,Autocomplete,我将此代码用于AutoCompleteTextView——因此当您删除最后一个字符以显示列表时。但是mAutoCompleteTextView.showDropDown()

我将此代码用于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();
            }
        }
    });
初始化小部件时,我记得类字段中的适配器。 使用此选项设置适配器

mAdapter=(ArrayAdapter)actv.getAdapter();//mAdapter是一个类字段
actv.setText(“Tim Hortons”);
actv.setSelection(0,actv.getText().length());
actv.setAdapter((ArrayAdapter)null);//关闭适配器
actv.requestFocus();
Handler=newhandler(){
公共无效handleMessage(消息消息消息){
((AutoCompleteTextView)msg.obj).setAdapter(mAdapter);
};
Message msg=mHandler.obtainMessage();
msg.obj=actv;
handler.sendMessageDelayed(msg,200);
希望这对你有帮助


为什么将代码放在PostTextChanged中?不在ContextChanged中?不要在ContextChanged中工作可能是因为s.toString从不匹配“”或者,当textfield为空时,可能不会触发PostTextChanged。通常它至少需要1个字符才能启动。是否要在删除所有字符时显示列表?是-如果所有字符都已删除,我想显示列表确定将此属性添加到textview mContactTxt.setFocusable(false);mContactTxt.setFocusableInTouchMode(false);mContactTxt.setText(“”);mContactTxt.setFocusable(true);mContactTxt.setFocusableInTouchMode(true);
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);