Keyboard doesn't show when EditText is clicked - java

I'm having a problem with the softkeyboard not showing when i click on a EditText.
The activity goes like this.
1. Activity starts
2. Dialog box opens with a custom keyboard
3. And then I try to click on an empty EditText field to put in data, but nothing happens. The field get focus, but keyboard doesn't show up.
I haven't done anything funky with disabling keyboard..
Anyone know whats going on?

If you're using AVD manager add a hardware property Keyboard support and set it to false.
That should disable the shown keyboard, and show the virtual one.

Related

How to stop alert dialog from shifting upwards when keyboard is shown

I have ran into some issue with android. The situation is currently, when I tap the editText field in the alert dialog, the dialog will shift up to make way for the keyboard. However, I have calculated that there is enough space between my dialog and the keyboard. The reason behind is to have the dialog box hide the content that is underneath it.
Question
Is there a way to stop the alert dialog box from shifting upwards ?
Add or change in AndroidManifest.xml for that activity tag.
<activity
android:name=".YourActivity"
android:windowSoftInputMode="adjustNothing" />
As long as you always need to show the keyboard immediately once the dialog opens rather than once a specific form widget inside gets focus (for instance, if your dialog just shows an EditText and a button), you can do the following:
AlertDialog alertToShow = alert.create();
alertToShow.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
alertToShow.show();
Rather than calling .show() on your builder immediately, you can instead call .create() which allows you to do some extra processing on it before you display it onto the screen.

set the cursor to search view automatically

I have a button in an activity, on clicking that button, I direct the user to a search activity with a search view in the toolbar..
I'm using android.support.v7.widget.SearchView, I managed to expand it automatically using searchView.setIconifiedByDefault(false) in onCreateOptionsMenu..
I also open the keypad automatically in activity onCreate, yet I still have to click in the searchView to start typing there, I want the cursor to be set there automatically..
any help?
call setIconifiedByDefault(false) when the searchview is intialized.
Sets the default or resting state of the search field. If true, a single search icon is shown by default and expands to show the text field and other buttons when pressed. Also, if the default state is iconified, then it collapses to that state when the close button is pressed. Changes to this property will take effect immediately.
Try the below, it worked for me once.
searchView.setIconifiedByDefault(true);
searchView.setFocusable(true);
searchView.setIconified(false);
searchView.requestFocusFromTouch();
Update: If you are Using android.support.v7.widget.SearchView the behaviour is very different. clearFocus is needed if you don’t want the keyboard pop-up all the time.
Also in the searchview layout, use <requestFocus /> tag.

How do you hide the keypad on activity change or when edit text is not enabled?

How do you hide the keypad?
I'm currently using the following code to hide the keypad. Is there a better way to do this?
Window window = getWindow();
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
You have the right idea for hiding the soft keyboard. You could probably use the SOFT_INPUT_STATE_HIDDEN flag instead of the ALWAYS_HIDDEN one, this would allow it so it will re-open when the user clicks in the EditText without the need to call setSoftInputMode() again.

Set focus on an edittext after using

I have an EditText that recieves input and prints in on the screen. I need to find a way wherein after click submit or enter, the phone will focus on the EditText
I tried
txtJoke.setFocusable(true);
txtJoke.setFocusableInTouchMode(true);
txtJoke.requestFocus();
and it doesn't work..
requestfocus works during onCreate..
I'm thinking of manually triggering a click an edittext..
You can use ...
Button newButton.setOnFocusChangeListener(new View.onFocusChangeListener) {....}
to specify where will be the focus go next.

EditText selects by default?

Whenever I have an EditText field in my android application, it is highlighted with the blinking cursor for input as soon as the activity is started (though the keyboard doesn't pop up). How can I disable this?
EditText and ListView are focusable in touch mode so when you launch your application by tapping on its icon (putting you into touch mode) the first one in your application will likely get focus. Had you entered your application by using the D-pad (moving you out of touch mode) the first Button, Spinner, EditText, or ListView would get the focus since they are all focusable.
I wouldn't get too hung up on the a View being in focus when your application starts but if you really can't stand the default way of handling focus, you could try giving focus to a TextView since it doesn't look different when it is in focus. Keep in mind that it isn't normally focusable in touch mode so you will need to enable it prior to requesting focus. Since this is a bit hacky, others (myself included) will caution you against going down this route and likely encourage you to accept the normal behavior.
View tv = findViewById(R.id.MyTextView);
tv.setFocusableInTouchMode(true);
tv.requestFocus();
PS: You may also want to check out this other SO question as it is nearly identical to yours.
You could call setFocusable(false) to avoid this. But if it should become focus later then maybe you have to call setFocusable(true) again later.

Categories