Android: AlertDialog с EditText не показывает клавиатуру автоматически - PullRequest
3 голосов
/ 22 августа 2011

У меня есть AlertDialog, который отображается два раза подряд.На Nexus S все работает так, как я ожидал, но на Wildfire клавиатура исчезает, когда диалоговое окно отображается во второй раз.

Должно быть, проблема с синхронизацией, потому что клавиатура отображается, когда яустановите точку останова в конструкторе и продолжайте оттуда.Может быть, onFocusChange - не то место, где нужно показывать клавиатуру.

Как это исправить?Что бы вы искали, чтобы найти причину этой проблемы?

/**
 * Show a dialog asking the user to confirm the PIN.
 */
private static abstract class PinConfirmationDialog extends AlertDialog {

    protected PinConfirmationDialog(Context context, final int titleResource) {
        super(context);
        setTitle(titleResource);

        // Set an EditText view to get user input 
        final EditText input = new EditText(context);
        InputFilter[] FilterArray = new InputFilter[1];
        FilterArray[0] = new InputFilter.LengthFilter(4);
        input.setFilters(FilterArray);
        input.setKeyListener(DigitsKeyListener.getInstance(false,true));
        input.setInputType(InputType.TYPE_CLASS_NUMBER
                | 16 /*InputType.TYPE_NUMBER_VARIATION_PASSWORD Since: API Level 11*/);
        input.setTransformationMethod(new PasswordTransformationMethod());
        setView(input);

        setButton(context.getString(R.string.okay_action), new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                onOkButtonClicked(input.getText().toString());
            }
        });
        setButton2(context.getString(R.string.cancel_action), new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                onCancelButtonClicked();
            }
        });

        input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                  getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                }
            }
        });
    }

    /**
     * OK Button was pressed
     * @param pinCode The code the user has entered
     */
    abstract void onOkButtonClicked(String pinCode);

    /**
     * Override method if needed
     */
    protected void onCancelButtonClicked() {
    }
}

Ответы [ 2 ]

0 голосов
/ 22 августа 2011

Вы можете попробовать это,

editText.setFocusable(true);
 requestfocus();
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);
0 голосов
/ 22 августа 2011

Попробуйте:

// Setting of the Keyboard
InputMethodManager imm = (InputMethodManager)   
getSystemService(Context.INPUT_METHOD_SERVICE);
// For SHOW_FORCED
imm.showSoftInput ( YOUEDITTEXT, InputMethodManager.SHOW_FORCED);

Надеюсь, это вам поможет!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...