在Android的下拉列表中滚动的autocompletetextview时关闭键盘 [英] Close keyboard when scrolling in dropdown on autocompletetextview in Android

查看:949
本文介绍了在Android的下拉列表中滚动的autocompletetextview时关闭键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我有它连接到一个Web服务,以便它显示我建议,我键入autocompletetextview。现在,我怎么能隐藏软键盘,当用户开始通过自动完成下拉滚动?我通过网络看了,但没有找到要detech上自动完成下拉触摸任何方法。

I have an autocompletetextview which I have linked it to a webservice so it shows me suggestions as I type. Now how can I hide the soft keyboard when the user starts scrolling through the autocomplete dropdown? I looked through the net but didnt find any method to detech touches on the autocomplete dropdown.

推荐答案

当用户再次开始滚动列表,显示键盘,如果用户倒是最好的解决办法我能想出这一点,是隐藏键盘再次TextView中。这pretty很多作品大部分操作系统版本和设备,不像其他的解决方案,你可以看到,比如设置dropDownHeight的高度。

The best solution I could come up for this, is hiding the keyboard when the user starts scrolling the list and showing the keyboard again, if the user touches on the textview again. This pretty much works for most of the OS versions and devices, unlike other solutions you could see, such as setting the height of the dropDownHeight.

下面是一个示例code隐藏键盘,当用户开始滚动。基本上,你需要创建你AutoCompleteTextView的适配器,触摸监听器。

Below is a sample code to hide the keyboard, when the user starts scrolling. Basically, you need to create a touch listener in your AutoCompleteTextView's adapter.

public View getView(final int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    ViewHolder holder;
    if (convertView == null) {
        convertView = inflater.inflate(viewResourceId, parent, false);
        holder = new ViewHolder();
        init(convertView, holder);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    convertView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                InputMethodManager imm = (InputMethodManager) getContext()
                        .getSystemService(
                                Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(
                        searchView.getWindowToken(), 0);
            }

            return false;
        }
    });

    setView(position, holder);
    return convertView;
}

这篇关于在Android的下拉列表中滚动的autocompletetextview时关闭键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆