Unclickable EditText on resume - android

I currently have an EditText inside a fragmented Tab, When you first enter the view the EditText only works correctly if i use
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
on the view, but it does allow my to hide the keyboard and bring it back be re-clicking.
However if i was to leave this view or if the phone goes to sleep for a moment and comes back the edit text is no longer clickable, I've tried forcing it to be focused using onresume but once you hide the keyboard you cannot regain focus again.
I feel as if i'm missing something regarding EditText Functionality in Fragments but i've had 0 luck finding anything relating to this problem.
Thanks for your time.

Rather then hiding keyboard from code, hide it from manifest on that activity. It will solve your problem i guess.
For hiding from manifest use this code -
<activity
android:name="com.app.xyz.youractivityname"
android:windowSoftInputMode="stateHidden" />

On your onResume you can do this:
EditText someEditText = (EditText)getActivity().findViewById(R.id.someEditText);
someEditText.requestFocus();
InputMethodManager mgr = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(someEditText, InputMethodManager.SHOW_IMPLICIT);

Related

Set android focus on touch?

I have this issue: in my app, when user taps on EditText bar, keyboard pops up. After that, it is impossible to get rid of keyboard. When back button is pressed, whole application just turn off.
How can I make sure, that when user taps on some other object (not EditText), keyboard will be removed? Or at least, how to make it possible to hide keyboard by tapping back button?
Thanks.
in xml for EditText this will make keyboard dismiss when press enter on keyboard
android:imeOptions="actionDone"
You can hide the keyboard simple by overriding onBackPressed in your Activity and using the following code:
InputMethodManager inputMethodManager = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(anyView.getWindowToken(), 0);
Note that anyView can be any view that is attached to your current window.
You can see it working in my app called Magic Annotator. See method hideSoftKeyboard()

Android onscreen keyboard without any other keyboard

I've looked at several questions and come across several posts, but i'm not able to figure out how to do this.
The following picture shows you the basic layout :
I've created a custom numpad and put it up on the repo.
Currently, when the app opens, the edit text has the focus but and anything i enter with the keyboard will go into the edittext box. This part of the functionality works fine.
Problem: When i touch the edittext again, system Input Method with its huge keyboard pops up. How do i completely block it from popping up? Or, can i tell the app to use only my keyboard instead of the system one? (Or is the only way to write a custom ime?)
i cannot use NULL type input at the manifest because doing that makes the caret in the edittext disappear and moreover if there are two edit texts, i wouldnt know which has focus.
Any help would be highly appreciated!
You can do a few things:
Programmatically hide it in the whole app:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Hide it from the view it would be attached to:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
Set the input type of the EditText to 0:
EditText yourEditText=(EditText)findViewById(R.id.editTextConvertValue);
yourEditText.setInputType(0);

Why does soft keyboard show up?

Is there any way to find out why the soft keyboard show up in one of my views ?
The app is quite big and it's not obvious why the keyboard gets enabled. Do you know any way to debug that?
You can use the following line of code in the activity's onCreate method to make sure the keyboard only pops up when a user clicks into an EditText
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
or
android:windowSoftInputMode="stateHidden"
In the manifest.

EditText has focus when Activity starts, but soft keyboard is not shown

as mentioned above, the keyboard does not show up, although the EditText is focused (orange border) and the cursor is blinking.
When I click into text field, it opens up, however I want it to be open right when the activity starts.
I tried setting android:windowSoftInputMode="stateVisible" in the activity, I tried showSoftInput(yourTextBox, InputMethodManager.SHOW_IMPLICIT); and also requestFocus().
But no success...
What could be the problem?
Try something like this:
EditText myEditText = (EditText) findViewById(R.id.editPasswd);
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(myEditText, InputMethodManager.SHOW_FORCED);
Are you testing on emulator? If you do, you should know that keyboard doesn't pop up on emulator :), but it does on a real device
Good luck,
Arkde
Another way to show the keyboard when the Activity is created is to add this code in your AndroidManifest file for the activity which you want to show the keyboard on starts :
<activity android:name=".UserLogin" android:windowSoftInputMode="stateAlwaysVisible"/>

How to set the focus on button?

Hi I have some EditTexts and a button at the bottom of the view. Upon starting the activity, the first EditText will gain focus and a keyboard will pop up. I want to upon starting the activity, the focus will be on the button instead of the EditText and the keyboard should not pop up. I tried running:
button.requestFocus();
The EditText still have focus and pops up the keyboard. How can I resolve this? Thanks.
Its trickier than it seems, but certainly possible. See here:
Stop EditText from gaining focus at Activity startup
Put android:windowSoftInputMode="stateHidden" to your Activity which contains EditText
<activity android:name=".YourActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
</activity>
You can force hide the keyboard by calling this on the EditText view
InputMethodManager mgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(myView.getWindowToken(), 0);
Hope this helps,
-serkan

Categories

Resources