I would like to know how best to hide the keyboard after entering text in EditText.
1) setonfocuschangelistener: only this listener is called when the "Finish" button is pressed or when the focus changes from one EditText to another? When I used this method, I could not hide the keyboard.
2) setOnTouchListener: When I used this, I could hide the keyboard, but I doubt there might be a problem with this. In this case, I add a touch listener to the root LinearLayout. The following code I used:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
txtUserName = (EditText)findViewById(R.id.txtUserName);
btnLogin = (Button)findViewById(R.id.btnLogin);
layoutView = (LinearLayout)findViewById(R.id.li);
layoutView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(txtUserName
.getWindowToken(), 0);
return true;
}
});
}
LinearLayout LinearLayouts. , , , , , .
, , (TextView). TextView (.. ), .
, touchListener ?
?