Question

Alright, another weird problem. I have activity Main.java and DialogLikeActivity.java.

In Main I have

EditText (articleNumber) - phone input type (in .XML)
Button (articleOK)
list (list)

On DialogLikeActivity (activity but styled with a Dialog theme and with android:windowSoftInputMode="stateAlwaysVisible" tag in Manifest) I have

EditText (articlePackaging) - phone input type (in .XML)
Button (finish)

What I want? When I enter Main activity keyboard is open with phone input type and that's fine. When I click on EditText field, fill in something and click OK static varible becomes in state 1 (always show keyboard) - it's just static variable in Main activity.

public static int keyboardMode = 1;

Clicking on OK opens up DialogLikeActivity with keyboard open (phone input type). When I click OK onResume of Main kicks in

@Override
public void onResume() {
    super.onResume();

    if (keyboardMode == 1) {
        showKeyboard(articleNumber);
    } else {
        hideKeyboard(articleNumber);
    }
}   

public static void showKeyboard(View view) {
    InputMethodManager mgr = (InputMethodManager) myContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);

    ((InputMethodManager) myContext.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, 0);

    articleNumber.setInputType(InputType.TYPE_CLASS_PHONE);
}

public static void hideKeyboard(View view) {
    InputMethodManager mgr = (InputMethodManager) myContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.hideSoftInputFromWindow(view.getWindowToken(), 0);

    articleNumber.setInputType(0);
}

// Listener to showKeyboard if user clicks on EditText field and set InputType to PHONE, insted it would remain (0)

    articleNumber.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showKeyboard(articleNumber);
        }
    });

// Listener so when user touches the list - it hides the keyboard and sets variable on 2 so keyboard is always HIDDEN

    list.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            hideKeyboard(articleNumber);
            keyboardMode = 2;

            return false;
        }
    });

// Listener so when user clicks on ArticleOK - keyboard is always OPEN

articleOk.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {               
                keyboardMode = 1;

                    Intent i = new Intent(NewOrderArticles.this, NewQuantityDialog.class);
                    i.putExtra("articleid", articleId);
                    startActivity(i);
            }
        }
    });

And ensures that keyboard is open with phone input type. If I howewer click/scroll through the list in Main keyboardMode variable becomes 2 (always hide) - so the keyboard hides (with hideKeyboard method called list.onTouch listener). If I click on some item in the list it again opens DialogLikeActivity with open keyboard and phone input type. If I click OK onResume in Main kicks in and hides keyboard (see code upthere).

How does that look like please see video (OK button in video is articleOK button) - Video (3,24 MB).

So actually - if I click OK (articleOK) button - keyboard always must be shown, if I, however start scrolling thorugh the list or click on some item in the list - keyboard must be shown only in DialogLikeActivity activity, otherwise in Main it must stay hidden (ofcourse if I click on EditText field on the top it opens up again).

On video you can see HTC Desire and everything works just the way I want, but - on Galaxy S the always show part is working, but if I tap/scroll the list, it open's up keyboard with letter type (!) instead of hiding it. Where's the problem?

So OK button - always show keyboard (in Main and DialogLikeActivity). If tap/scroll the list show keyboard only in DialogLikeActivity.

Was it helpful?

Solution

I have the same problem with an EditText that pops up the keyboard with numbers. After clicking on OK or Cancel, the virtual keyboard does not hide and shows keyboard with letter type, on the Samsung Galaxy S device. It's working fine on Emulators 2.1 or 2.2 and my HTC Hero, but not on Samsung Galaxy S device with 2.2. I also tried: mgr.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); but still no chance

EDIT: ok, problem solved with this line only:

mgr.toggleSoftInput(0, 0);

and without these 2 lines:

mgr.hideSoftInputFromWindow(view.getWindowToken(), 0);
articleNumber.setInputType(0);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top