您是否設置了密鑰監聽器?
你並沒有真正說明你是如何知道用戶輸入文本的,因此我假定他們正按下軟鍵盤上的輸入按鈕。以下是我如何處理這種情況。我在一個對話框和一個成功的活動中使用它。希望能幫助到你。
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