简体   繁体   English

Android:在AutocompleteTextView中不显示软键盘

[英]Android: don't show soft keyboard in AutocompleteTextView

I have an AutocompleteTextView to select a train station, which is using two different adapters : 我有一个AutocompleteTextView来选择使用两个不同适配器的火车站:

ADAPTER 1 : containing a fixed list of recent and nearby stations ( DOESN'T require a soft keyboard for filtering by typing) 适配器1 :包含最近和附近电台的固定列表( 不需要软键盘即可通过键入进行过滤)
ADAPTER 2 : containing the cursor to the sqlite database of stations ( DOES require a soft keyboard for filtering by typing) 适配器2 :将光标包含到工作站的sqlite数据库中( 确实需要软键盘才能通过键入进行过滤)

So, I would like to prevent the soft keyboard from showing when the AutocompleteTextView gets the focus and the ADAPTER 1 is used, but I haven't found a way yet. 因此,我想防止在AutocompleteTextView获得焦点并使用ADAPTER 1时显示软键盘,但是我还没有找到解决方法。

I am currently using this, but the soft keyboard keeps popping up: 我当前正在使用它,但是软键盘不断弹出:
InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0);

I finally found a way! 我终于找到了方法!
On the onFocusChange you first set the focus to its parent and after that you call showDropDown() to display the dropdown. 在onFocusChange上,首先将焦点设置为其父对象,然后调用showDropDown()以显示下拉列表。 In this way the keyboard doesn't pop up, because the AutocompleteTextView doesn't have the focus! 这样,键盘不会弹出,因为AutocompleteTextView没有焦点!

    setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if(hasFocus) {
                setAdapter(Adapter1);
                ((ViewGroup)getParent()).setFocusableInTouchMode(true);
                ((ViewGroup)getParent()).requestFocus();
                showDropDown();
            }
        }
    });

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

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