Problem:
I want to hide the keyboard when the "Add" button is clicked. There are two EditText on the screen. The keyboard does not appear when the operation starts, which is good, but it does not disappear when the button is pressed.

Here are all the possible questions from Stack Overflow that I saw, the answers to which do not help me:
Close / Hide Android Soft Keyboard
Programmatically hide / show Android soft keyboard
How to hide Soft Keyboard when starting activity
How to hide soft keyboard on android by clicking outside EditText?
and many others.
Here is my code:
Addactivity
public class AddActivity extends ActionBarActivity { EditText text1,text2; DbHelper db; ListView l; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add); db = new DbHelper(this); l = (ListView) findViewById(R.id.listInAddActivity); text1 = (EditText) findViewById(R.id.i1); text2 = (EditText) findViewById(R.id.i2);
Most answers relate to the InputManager method, but it does not work for me, i.e. does not hide the keyboard when you click on the button. Here is another variant of InputManager I:
View view = this.getCurrentFocus(); if (view != null) { InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
I also tried this:
getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN );
and this also does not work (the keyboard is not hidden when the button is pressed).
I also tried:
<activity android:name=".AddActivity" android:label="@string/app_name" android:parentActivityName=".MainActivity" android:windowSoftInputMode="stateAlwaysHidden"> </activity>
and
<activity android:name=".AddActivity" android:label="@string/app_name" android:parentActivityName=".MainActivity" android:windowSoftInputMode="stateAlwaysHidden"> </activity>
With this application, my application stopped working:
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
This completely hid the keyboard (the keyboard did not display even when EditText pressed):
text1.setInputType(InputType.TYPE_NULL); text2.setInputType(InputType.TYPE_NULL);