建议未在AutoCompleteTextView中显示

use*_*071 2 android autocompletetextview

我的布局中有一个AutoCompleteTextView.当用户输入"@"字符时,我必须向他们显示一些建议.它通常是我从互联网上得到它的名字.

我得到了名字,我创建了一个ArrayAdapter,如下所示.

autoCtextView.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            // TODO Auto-generated method stub
            String lsatChar = s.toString().substring(s.length()-1,s.length()); 
            if(lsatChar.equals("@")) {
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(DisplayQuestionDetails.this, 
                         android.R.layout.simple_list_item_1, namesLsist);
                autoCtextView.setAdapter(adapter);
            }


        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub

        }
    });
Run Code Online (Sandbox Code Playgroud)

但这些建议没有显示出来.我做错了吗?请询问是否需要澄清问题

lyn*_*gon 6

你错过了autoCtextView.setThreshold(1);吗?

(从第一个角色开始工作)

例如演示:

String[] strList={"a","aaa","aabb","b","bbc","cbb","c","cdd","caa","d","ddc","dda","e","eea","ebc","aec"};  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  

        //Creating the instance of ArrayAdapter containing list
           ArrayAdapter<String> adapter = new ArrayAdapter<String>  
            (this,android.R.layout.select_dialog_item,strList);  

        //Getting the instance of AutoCompleteTextView  
           AutoCompleteTextView autoCtextView= (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);  
           autoCtextView.setThreshold(1);         //to start working from first character  
           autoCtextView.setAdapter(adapter);//set the adapter data to the AutoCompleteTextView  




}  
Run Code Online (Sandbox Code Playgroud)