14

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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
user642347
  • 321
  • 1
  • 4
  • 6

9 Answers9

26

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();
neevek
  • 11,760
  • 8
  • 55
  • 73
10

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();
5

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();
    }
}
YetAnotherUser
  • 527
  • 5
  • 12
4

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/

Ricardo Vieira
  • 1,738
  • 1
  • 18
  • 26
android developer
  • 114,585
  • 152
  • 739
  • 1,270
3

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"/>
ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
2

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

Keith
  • 1,123
  • 9
  • 22
1

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);
    }
}
Muhammad Adil
  • 4,358
  • 3
  • 32
  • 36
  • Yeah but with approach you'll get unexpected behaviors. For instance, if you background your app while IMM is forced open, it'll stay open, even on the home screen. :) – worked Apr 01 '16 at 18:59
1

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); 
Joachim Rohde
  • 5,915
  • 2
  • 29
  • 46
Suman
  • 4,221
  • 7
  • 44
  • 64
0

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