showing softkeyboard in android on landscape orientation - android

EditText textView = (EditText ) findViewById(R.id.editText1);
textView.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(textView, InputMethodManager.SHOW_IMPLICIT);
I use this code to open soft keyboard automatically .
it works fine in normal situation but when I change it to landscape orientation android:screenOrientation="landscape"
in manifest, it stops working.
what's wrong with it?

You need to show it forcefully.
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
imm.showSoftInput(textView, InputMethodManager.SHOW_FORCED);

Related

How to always show soft keyboard and do not let it be closed?

I want to know 2 things
how to always show soft keyboard and do not let it be closed ( even when back or OK button was pressed ) ?
and how can I get an input from it?
I have already tried this code:
EditText yourEditText= (EditText) findViewById(R.id.ed);
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
with these variants:
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
imm.toggleSoftInputFromWindow( yourEditText.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
Use android:windowSoftInputMode="stateAlwaysVisible" in to AndroidManifest.xml file
Like this:
<activity android:name=".YourActivity"
android:label="#string/app_name"
android:windowSoftInputMode="stateAlwaysVisible" /> // OR stateVisible
If that activity having EditText so when ever Activity will start
your Keyboard automatically open
If you want to still open Keyboad after use done any operation then do this via programetically
InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInputFromWindow(
linearLayout.getApplicationWindowToken(),
InputMethodManager.SHOW_FORCED, 0);
OR
To Show Soft Keyboard
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(EDITABLE_VIEW,
InputMethodManager.SHOW_IMPLICIT);
OR
EDITABLE_VIEW can be any view which has focus on screen like
mEditText = (EditText) findViewById(R.id.editText);
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText ,
InputMethodManager.SHOW_IMPLICIT);
OR
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInputFromInputMethod(editText.getWindowToken(), 0);
Documentation

Android: force keyboard to appear and focus on EditText

Thanks in advance for the help.
I would like a keyboard to appear at the end or during the execution of the following code.
// edit text
EditText editText = new EditText(activity);
editText.setBackgroundColor(Color.WHITE);
editText.setGravity(Gravity.TOP);
editText.setText("Type here...");
RelativeLayout relativeLayoutEditText = new RelativeLayout(activity);
RelativeLayout.LayoutParams paramRelativeLayoutEditText = new RelativeLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, 43 * display.getHeight() / 80 );
paramRelativeLayoutEditText.addRule(RelativeLayout.ALIGN_PARENT_TOP);
relativeLayoutEditText.addView(editText,paramRelativeLayoutEditText);
// add all created views to rootView
rootView.addView(relativeLayoutEditText, paramEditText);
// open keyboard
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
but the keyboard only appears after touching the editText field (ie with my finger). Is there a way that I can make the board automatically appear without using a physical touch?
As an aside I know that how I am specifying the width and height isn't exactly the right way to do things.
Thanks to #Shubham's link I was able to figure it out. The solution was not the answer given in the link, however. It was the second answer.
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
Edit:
once using the above solution the keyboard will remain on the screen until a user presses either the back button or the home button (sometimes it takes a few times). To remove the keyboard use this
imm.toggleSoftInputFromWindow(rootView.getWindowToken(), 0,0);
in my case rootView is the rootView of the current activity. I have not tested this to see if this will work on child views.
Add
editText.requestFocus();
Try this:
EditText editText = (EditText ) findViewById(R.id.myTextViewId);
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
ensure that the edittext is focusable in touch mode. You can do it two way.
In xml:
android:focusableInTouchMode="true"
in Java:
editText.setFocusableInTouchMode(true);
Try This
EditText textView = (EditText ) findViewById(R.id.myTextViewId);
textView.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(textView, InputMethodManager.SHOW_IMPLICIT);
http://developer.android.com/reference/android/view/View.html#requestFocus()
Possible answer link. Many of the above are also sourced from this link.
Try This :
EditText textView = (EditText )findViewById(R.id.myTextViewId);
textView.requestFocus();
InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(textView, InputMethodManager.SHOW_IMPLICIT);
this will show the keypad
InputMethodManager imm = (InputMethodManager)
OrderMainActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(txtCustomerId, InputMethodManager.SHOW_IMPLICIT);
enter your activity name instead of this if you calling keypad from the listeners eg. button click

edit text not editable after using requestFocus on Gingerbread and below?

I have a edit text and i set the following
editText.requestFocus()
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(ediText, InputMethodManager.SHOW_IMPLICIT);
It works perfectly fine in ICS and JellyBean but in Gingerbread/Froyo etc the edit text is not editable(whatever user inputs does not show in the edit text) . I have no clue for this wierd behaviour . Any idea to getaround this ?
Try this:
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
Only change getActivity() to getApplicationContext() then i think it will be worked in Gingerbread to ics.
EditText et = (EditText) findViewById(R.id.et);
et.requestFocus();
InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);

Controlling the Soft Keyboard during onClick - Android

I had an issue where if user was typing and hit submit, the keyboard would not go away, so I found this code to fix that issue (by placing this in the onClick method):
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
However, if the user manually closed the keyboard, then clicked submit, I found the code above would bring the keyboard back -- not good.
The question:
Is there better code to use? OR can I just say something like =
if (keyboard = displayed) {
// do code above
} else {
// do nothing
}
To hide the keyboard:
final InputMethodManager inputMethodManager =
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
To show it:
final InputMethodManager inputMethodManager =
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_FORCED);

How to display the soft keyboard only on the click event of edittext in android?

My android Activity has an EditText. Whenever the screen loads the soft keyboard automatically pops up. This obscures the visibility of my screen. I want to display the soft keyboard only on the click event of that EditText.
How can I do this?
In my code I got something like this:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(password.getWindowToken(), 0);
imm.hideSoftInputFromWindow(username.getWindowToken(), 0);
where password and username are TextEdit views.
And to show:
imm.showSoftInputFromWindow(username.getWindowToken(), 0);
Try with this..
EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
To Close u can use
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
This is how to show and/or how to close it.
So when you start the activity, use first the close code.

Categories

Resources