繁体   English   中英

如何在AutoCompleteTextView上设置文本

[英]How to set text on AutoCompleteTextView

我在AutoCompleteTextView上设置默认值时遇到麻烦。 首先,我尝试做setText("default value") 然后,我搜索并尝试了以下操作:

autoText.postDelayed(new Runnable() {
    @Override
    public void run() {
        autoText.showDropDown();
    }
},500);
autoText.setText("chi");
autoText.setSelection(tvNewRestoAddress.getText().length());

但它仍然不起作用。 有什么建议么?

尝试这个

  AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.edt);
    String[] array = {"abc", "bcd", "cde", "def", "efg", "fgh", "PREM"};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>
            (this, android.R.layout.select_dialog_item, array);

    autoCompleteTextView.setAdapter(adapter);
    autoCompleteTextView.postDelayed(new Runnable() {
        @Override
        public void run() {
            autoCompleteTextView.setText("PREM");
            autoCompleteTextView.showDropDown();

        }
    }, 10);
 String[] fruits = {"Apple", "Banana", "Cherry", "Date", "Grape", "Kiwi", "Mango", "Pear"};
     ArrayAdapter<String> adapter = new ArrayAdapter<String>
                    (this, android.R.layout.select_dialog_item, fruits);
     AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
            actv.setThreshold(1);//will start working from first character
            actv.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM