I want to open the soft keyboard in android automatically after opening the activity . I used the code mentioned here Close/hide the Android Soft Keyboard but it doesn't work. This is my code.
final EditText txtName = (EditText) findViewById(R.id.etxt_hidenprac);
txtName.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
txtName.post(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) Practice.this.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(txtName, InputMethodManager.SHOW_IMPLICIT);
}
});
}
});
txtName.requestFocus();
<activity
android:name="com.example.moisun01.Practice"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateVisible">
</activity>
I found it why it doesn't work . its because my layout is in landscape orientation. and in portrate orientation it works fine. but my App is in landscape . is there any solution for this problem?