Keyboard not shown when i click on edittextview in android? - android

When i click on the edittextview then some times keyboard shown or some times keyboard are not shown.
In android 2.1 it show the keyboard when i click on the edittextview
but when i start same application it on android 2.2 then it not show the keyboard.
Help me how to show that problem.

OK, This might be a late response, but it worked.
I have met this problem on android 2.1 and 2.3.x(not tested on other versions of SDKs).
I noticed a strange thing that when my click on the EditText was unable to open the keyboard, I pressed the BACK button to show an alert dialog and then I canceled(closed) it, and clicked the EditText again, now the keyboard was brought to life again.
From that I can conclude that the keyboard will always show for the EditText if the EditText does not previously own focus(showing an alert dialog over the EditText view will make the EditText to lose focus).
so call the function below on your EditText when it is brought to front:
mEditText.clearFocus();
or
parentViewThatContainsEditTextView.clearFocus();

I had a similar problem on Galaxy S3 (displaying EditText controls on a PopupWindow - the keyboard was never showing). This solved my issue:
final PopupWindow popUp = new PopupWindow(vbl.getMainLayout());
[....]
popUp.setFocusable(true);
popUp.update();

I didn't want to EditText lose a focus using editText.clearFocus(). Came up to this solution.
#Override
public void onResume() {
super.onResume();
if (Build.VERSION.SDK_INT < 11) {
editText.clearFocus();
editText.requestFocus();
}
}

here's a possible solution:
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(final View v, final boolean hasFocus) {
if (hasFocus && editText.isEnabled() && editText.isFocusable()) {
editText.post(new Runnable() {
#Override
public void run() {
final InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText,InputMethodManager.SHOW_IMPLICIT);
}
});
}
}
});
code is based on the next link:
http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/

In my case it was in a PopupWindow and I simply needed to call popupWindow.setFocusable(true)

I had this same problem when displaying an EditText in a DialogFragment. Despite the EditText getting focus (i.e., when clicked, it showed the flashing caret), the keyboard did not display.
My solution was to add a dummy EditText to the uppermost view of my DialogFragment.
<EditText
android:id="#+id/editTextFix"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/fix"
android:importantForAutofill="no"
tools:targetApi="o"
android:inputType="text"
android:visibility="gone"/>

Possible scenarios:
1) On clicking the EditText, usually the keyboard comes up. But if you press the back key button in the emulator the keyboard (not the screen keyboard) dimisses.
2) In code you can disable the keyboard on clicking the EditText by setting a flag.
InputMethodManager inputmethodmgr= (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputmethodmgr.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

It works like a charm, In a case if you even want to hide on click of the edittextView.
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
displayKeyboard();
}
});
private void displayKeyboard(){
if (textView != null) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInputFromWindow(textView.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
}
}

In your parent view check if there is android:descendantFocusability="blocksDescendants"
remove it.

Related

Keyboard hidden when EditText focused

I have two fragments in one Activity and both of the fragments contain one EditText. When the the first EditText is focused (keyboard shown) and the user presses the next button of the keyboard, I am transferring the focus to the EditText in the second fragment by using this code:
View next = autoCompleteTextView.focusSearch(View.FOCUS_DOWN);
if (next != null) {
next.requestFocus();
}
The second EditText receives the focus as it should (the cursor starts blinking in it) but the keyboard that was shown, gets hidden.
I don't understand why this happens. I tried million different solutions, to force the keyboard to be shown again but nothing works. I don't know why it gets hidden in the first place, I am just transferring focus.
The only thing that worked for me is this:
mComposeMsgBody.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus && mComposeMsgBody.isEnabled()) {
mComposeMsgBody.post(new Runnable() {
#Override
public void run() {
final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mComposeMsgBody, InputMethodManager.SHOW_IMPLICIT);
}
});
}
}
});
But it is not ideal, since the keyboard tries to get hidden, and then I am forcing it go up, so there is this 1 second down-up movement that the keyboard does. If someone has a better solution for just transferring focus without the keyboard doing anything, please post an answer.

How to prevent focus on Activity start [duplicate]

This question already has answers here:
How to stop EditText from gaining focus when an activity starts in Android?
(54 answers)
Closed 5 years ago.
I have an Activity with only one EdtiText. When that Activity starts, the EditText is focused and the soft keyboard is shown. This seem to happen after onResume, because when I programmatically hide the keyboard in onResume it doesn't work. When I do this:
#Override
protected void onResume() {
super.onResume();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
//If no view currently has focus, create a new one, just so we can grab a window token from it
imm.hideSoftInputFromWindow(etBarcode.getWindowToken(), 0);
}
}, 500);
}
it hides it (after popping up shortly).
Is there an event on an EditText I can use to preven the keyboard popping up? Or some other way of preventing it to show?
Update focusableInTouchMode does not do what I want, because when set to true the keyboard pops up, when set to false it is not focusable at all.
// Add following code in activity onCreate
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
For parent layout android:focusableInTouchMode="true"
You can set property of Layout like
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
The problem is very complicated, as it's about views getting the focus, and how it's handled by all the layout, about the touch mode being focusable, and last but not least about how the soft keyboard handles that.
But this works for me:
In manifest:
android:windowSoftInputMode="stateHidden|stateAlwaysHidden"
In layout:
android:focusable="true"
android:focusableInTouchMode="true"
and last but not least, touch listener set to the EditText to prevent the soft keyboard to show up once touched:
mMyText.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// forward the touch event to the view (for instance edit text will update the cursor to the touched position), then
// prevent the soft keyboard from popping up and consume the event
v.onTouchEvent(event);
disableSoftKeyboard(MyActivity.this);
return true;
}
});
whereas the method does more or less what you're doing already:
public void disableSoftKeyboard(#NonNull Activity activity) {
View view = activity.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
} else {
activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
}
Hope it helps, and also that I didn't forget anything :)

Android softkeyboard not triggerring

I have multiple EditText on my screen and one of them is focussed. The softkeyboard does not trigger as soon as the screen pops up. I want the soft keyboard to trigger as soon as the screen pops up. It works well if I don't implement the onFocusChangeListener(). However I need the onFocusChangeListener() to detect which editText is focused. I have tried setting setFocusable(true) and setFocusableInTouchMode(true). Also i don't want to modify the android:windowSoftInputMode property in AndroidMenifest.xml. I have the following criteria :
onFocusChangeListener implemented (to detect which edittext is focused)
No modifications in AndroidMenifest.xml
Here is my code snippet
final InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
mInput.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
mIsFocused = hasFocus;
if(hasFocus)
inputMethodManager.showSoftInput(mInput, InputMethodManager.SHOW_IMPLICIT);
}
});
Any suggestions ?
You can open softkeyboard programmatically
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
You can try using inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0).
Source: Stackoverflow post

supressed the softkeyboard tapping on edittext box does not respond to every tap

The code that I am using to suppress the softkeyboard from appearing works about half the time. Any ideas why and how to go about fixing it. Here is my code.
public void time(View v) {
InputMethodManager imm = (InputMethodManager) getSystemService(Conte xt.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(time.getWindowToken(), 0);
time.setVisibility(View.VISIBLE);
new TimePickerDialog(report.this, t,
dateAndTime.get(Calendar.HOUR_OF_DAY),
dateAndTime.get(Calendar.MINUTE), true).show();
}
I got it to work by adding
date.setInputType(0);
time.setInputType(0);
in the Oncreate area. However now it does not always respond to the first tap on the edittext box. Is this an problem only on the emulator?

Android EditTExt query

I stuck with one issue in my current application. I have one editText and i have set it Enables = false in XML file. I have to buttons also named as EDIT and DONE.
Problem.
When application launches it works fine. EditText is not having focus and when i click on editext keyboard appears and i can edit text in edit text.
if(v==Edit)
{
//PurchaseAddressdata.setFocusable(true);
Edit.setVisibility(Button.INVISIBLE);
done.setVisibility(Button.VISIBLE);
PurchaseAddressdata.setClickable(true);
PurchaseAddressdata.setEnabled(true);
PurchaseAddressdata.setCursorVisible(true);
PurchaseAddressdata.setSelection(PurchaseAddressdata.getText().length());
}
if(v==done)
{
Edit.setVisibility(Button.VISIBLE);
done.setVisibility(Button.INVISIBLE);
PurchaseAddressdata.setCursorVisible(false);
PurchaseAddressdata.setClickable(false);
}
But the problem is when i click on editext keyboard is appearing. I want when i press Edit button then only keyboard will appear.
Thanks
Set the onFocusChangeListener listener of the edit text field to this so that it hides the keyboard when focused.
boolean display_keyboard = false;
edittext.setOnFocusChangeListener(new OnFocusChangeListener()
{
public void onFocusChange(View view, boolean arg1)
{
if (!display_keyboard)
{
InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
});
Then when the Edit button is clicked, set displaykeyboard = true; and move the focus back to the edittext
try this code it works for me.
editText.setInputType(0);
and in onClick()
editText.setInputtype(InputType.TYPE_CLASS_TEXT);

Categories

Resources