您是否设置了密钥监听器?
你并没有真正说明你是如何知道用户输入文本的,因此我假定他们正按下软键盘上的输入按钮。以下是我如何处理这种情况。我在一个对话框和一个成功的活动中使用它。希望能帮助到你。
this.setOnKeyListener(new OnKeyListener()
{
/**
* This listens for the user to press the enter button on
* the keyboard and then hides the virtual keyboard
*/
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event)
{
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN ) &&
(keyCode == KeyEvent.KEYCODE_ENTER) )
{
// hide virtual keyboard
InputMethodManager imm =
(InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(sessionTag.getWindowToken(), 0);
return true;
}
return false;
}
});
这是它,因为我失去了重点的EditText框上面显示我的代码隐藏键盘,但重点是针对由此拉开了键盘对我将在未来的EditText框。为了解决这个问题,我输入了两个命令来隐藏键盘,一个用于我离开的edittext框,另一个用于我刚刚关注的编辑框: InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(myEditText1.getWindowToken(),0); imm.hideSoftInputFromWindow(myEditText2.getWindowToken(),0); – 2011-02-25 16:15:00