隐藏键盘当点击超过列表视图

隐藏键盘当点击超过列表视图

本文介绍了隐藏键盘当点击超过列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个搜索视图以及其下的列表视图中包含了一些数据时,我点击的搜索视图键盘开放是那么明显,但我想隐藏键盘时,用户只需轻按在搜索视图,不输入在搜索视图什么,我想隐藏它,当用户点击列表视图$ P $下面psent。

我是pretty的肯定,我不能够澄清的问题,这就是为什么我添加了一些花絮。

解决方案

使用下面的方法来隐藏你的键盘

 公共静态无效hideKeyboard(上下文的背景下){

    尝试 {
        InputMethodManager inputManager =(InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);

        查看查看=((活动)范围内).getCurrentFocus();
        如果(查看!= NULL){
            inputManager.hideSoftInputFromWindow(view.getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }赶上(例外五){
        e.printStackTrace();
    }
}
 

假设你的列表视图 LV

  lv.setOnItemClickListener(新OnItemClickListener(){
      @覆盖
      公共无效onItemClick(适配器视图<>母公司视图中查看,INT位置,长的id){
          hideKeyboard();
     }
});
 

i am having a search view and a list view below that contains some data when i tap on the search view key board open which is so obvious but i want to hide the keyboard when user just tap on search view and does not type anything in the search view i want hide it when user click on the list view present below.

I am pretty sure that i am not able to clarify the question that's why i am adding some snap shots.

解决方案

Use the following method to hide your keyboard

public static void hideKeyboard( Context context ) {

    try {
        InputMethodManager inputManager = ( InputMethodManager ) context.getSystemService( Context.INPUT_METHOD_SERVICE );

        View view = ( ( Activity ) context ).getCurrentFocus();
        if ( view != null ) {
            inputManager.hideSoftInputFromWindow( view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS );
        }
    } catch ( Exception e ) {
        e.printStackTrace();
    }
}

Assuming your listview is lv

lv.setOnItemClickListener(new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
          hideKeyboard();
     }
});

这篇关于隐藏键盘当点击超过列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 21:43