如何在android中从ListViewAdapter隐藏默认键盘

如何在android中从ListViewAdapter隐藏默认键盘,android,listview,android-edittext,hide,android-softkeyboard,Android,Listview,Android Edittext,Hide,Android Softkeyboard,我使用ListViewAdapter在主页上绑定ListView,并使用自定义键盘。但当我点击EditText时,默认键盘显示 我尝试使用以下代码隐藏它: InputMethodManager mgr = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); mgr.hideSoftInputFromWindow(diesel.getWindowToken(

我使用ListViewAdapter在主页上绑定ListView,并使用自定义键盘。但当我点击EditText时,默认键盘显示

我尝试使用以下代码隐藏它:

InputMethodManager mgr = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
                    mgr.hideSoftInputFromWindow(diesel.getWindowToken(), 0);

activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
但它不起作用


如何从ListViewAdapter中隐藏默认键盘?

适配器不是执行任何与UI相关活动的正确位置。

我终于找到了它。我解决了这个问题。 刚刚添加到ListViewAdapter的下一行

(EditTextName).setInputType(0)


现在,它不会在编辑文本单击或触摸时打开默认键盘。

如果要在按钮单击等事件中隐藏键盘,请使用此选项

public void onClick(View v)
{
     InputMethodManager imm = (InputMethodManager) v.getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}

这是最好的解决方案,因为它没有副作用