i am adding a spinner, an image and an editText in a linearLayout everytime i click a button.
Now whenever i add this layout , editText shows blinking, means it has focus but the keyboard won't show up. Even i click on it, the keyboard won't show up. What most i can do is to click somewhere else and then back at the editText to make it show keyboard and proper focus.
I am using following code, how can i fix this bug.
viewHolder.title = (EditText) view.findViewById(R.id.AddNewDetail);
view.setTag(viewHolder);
layout.addView(view);
i think you should force the softkeyboard show.
((InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(editText,
InputMethodManager.SHOW_FORCED);
and close it
((InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(editText.getWindowToken(),
0);
and focus on edittext
editText.requestFocus();
May you have added the below line in for your activity in manifeast file
android:windowSoftInputMode="stateHidden"
try removing it or you can manaually use the requestfocus method to get focus. try the below method.
edittext.requestFocus();
Related
I have an EditText inside a CardView.
When the CardView is selected, I request focus for the EditText, see below:
cardProblem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//request focus
etProblem.requestFocus();
//display keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(etProblem, InputMethodManager.SHOW_IMPLICIT);
}
});
The problem is that I don't want the EditText to be clickable (currently when I tap on the EditText it gets focus).
I understand that when I don't want it to be clickable, I can add:
android:clickable="false"
android:focusable="false"
But in this situation I can't set focusable to false because the EditText needs focus when I want to edit it.
Any ideas how I can resolve this?
I have resolve this, sort of...
Since I don't have time to waste, I went with the following:
I decided to set the visibility of EditText to invisible and when the CardView is selected I make the EditText visible then request focus.
Maybe it helps you:
create a fake EditText as a first child in your CardView and set the width and height to zero or set visibility to gone, so he will get the focus by default and the foucus in your main EditText will be removed and when you need to set focus to it just request the focus :
etProblem.requestFocus();
I am showing a list with messages and each message's row has a comment button.When i click on comment button opens a comment box with edit text and button for submitting the comment.When comment box appears on screen keypad also appears for entering text.If i pressed home button before entering text then application goes background but keypad remains on screen.This is the thing irritating me.For custom list i am using a custom adapter and code for comment box is written in that adapter.I tried using
inputmgr.hideSoftInputFromWindow(txtComments.getWindowToken(), 0);
but it is not working. So how i can hide this keypad programmatically.
Try using the code in https://stackoverflow.com/a/1109108/1904479. Hope you are not testing it in Android version 4.1.
please use this method to hide soft keyboard.
public static void hideSoftKeyboard(Activity context) {
InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputManager != null)
inputManager.hideSoftInputFromWindow(context.getWindow().getDecorView().getApplicationWindowToken(), 0);
context.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
KeyEvent.KEYCODE_HOME can NOT be intercepted. You can hide the keypad inputmgr.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0); in onStop() method of your activity.
It does not require token from focused view editText.
Is it possible to change the label of the right-down button (OK-Button) in the default android-keyboard? I want to set my own text on it and I have tried the following code:
EditText et = (EditText) findviewById(...);
et.setImeOptions(EditorInfo.IME_ACTION_DONE);
et.setImeActionLabel("myLabel", EditorInfo.IME_ACTION_DONE);
However, the Label I see on the Button is the default from EditorInfo.IME_ACTION_DONE namely "OK". Should I adapt propely the above code, or is there another way to accomplish it?
You forgot
editText.setInputType(InputType.TYPE_CLASS_TEXT);
Otherwise the EditText defaults to TYPE_CLASS_TEXT | TYPE_TEXT_FLAG_MULTI_LINE, which always has the "enter as line break" key instead of IME_ACTION_DONE.
In my app, I have a dialog with EditText. I have coded it in such a way that as soon as the dialog shows up,the soft keyboard shows up, the edit text will get focus , all the existing text in the editText is preselected. And user can start typing. This all works fine when I am holding my phone in portrait orientation. But the same thing does not work when I have phone in landscape orientation. Part of my code in my fragment is pasted below.
final EditText inputDeviceId = new EditText(getActivity());
inputDeviceId.setInputType(InputType.TYPE_CLASS_TEXT);
String savedDevId = getDeviceID();
inputDeviceId.setText(savedDevId);
inputDeviceId.setSelectAllOnFocus(true);
// some more code ... to create dialog , ok cancel buttons then,
final AlertDialog alertDialog = alertDialogBuilder.create();
inputDeviceId.setOnFocusChangeListener(new View.OnFocusChangeListener() {
if(hasFocus){
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
});
alertDialog.show();
Now this all works in portrait orientation and does not work in landscape.
In landscape mode the dialog with edittext shows up , it has focus and existing text is preselected but it does not show the keyboard. User has to click in the editText for keyboard to come up. Why? I am using nexus-5 to test.
I have created a dialog box like so using a custom layout:
dialog = new Dialog(FetchMenu.this, R.style.CustomDialogTheme);
dialog.setContentView(R.layout.custom_dialog_iab);
dialog.show();
I am now trying to edit a textbox within 'layout.custom_dialog_iab' for example:
TextView text = (TextView) findViewById(R.id.all_topics_unlock_button);
text.setText("Purchased");
My Question: How do I get the right context to be able to edit the textboxes?
P.S. I have tried 'dialog.getContext()' but still keep throwing null pointers?
You need to use:
TextView text = (TextView) dialog.findViewById(R.id.all_topics_unlock_button);
Note the dialog. in front of findViewById
regular findViewById() will search your activity layout rather than the dialog layout.