键盘不会自动显示

时间:2012-09-21 12:49:18

标签: android

我有一个alertdialog,当用户点击按钮时显示:

public class CommentDialog {

public static void buildDialog(final Context context,
        final String identifier, Boolean automaticKeyboard,
        final int idToUpdate) {


    AlertDialog.Builder alert = new AlertDialog.Builder(context);
    alert.setIcon(ViewBuilder.getDrawableFromDB("text.png"));
    alert.setTitle("Commentaar");

    // Edittext configuration//
    final EditText input = new EditText(context);

    String currentComment = EnteredValues.getInstance()
            .getValueForIdentifier(identifier);

    if (currentComment != null) {
        input.setText(currentComment);
        input.setSelection(currentComment.length());
    }

    input.setHint("Gelieve uw commentaar in te voeren.");

    Display display = ((WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int width = display.getWidth();

    input.setMinimumWidth(width);
    input.setMaxLines(3);
    input.setImeOptions(EditorInfo.IME_ACTION_DONE);
    input.setFocusableInTouchMode(true);
    input.requestFocus();


    final InputMethodManager inputMethodManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.showSoftInput(input,
            InputMethodManager.SHOW_IMPLICIT);

    // Add edittext to dialog
    alert.setView(input);

    // Set actions of dialog
    alert.setPositiveButton("Bewaren",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    String value = input.getText().toString();

                    EnteredValues.getInstance().addValue(identifier, value);

                    View v = ShowScreenActivity.mActivity
                            .findViewById(idToUpdate);
                    EditText e = ((EditText) v);
                    e.setText(value);
                    e.setSelection(e.getText().length());

                    return;
                }
            });

    alert.setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    return;
                }
            });

    alert.show();
}
}

我尝试了几件事,但键盘没有自动显示。 它似乎也依赖于这些设备,带有蜂窝状的星系标签10.1,键盘显示出来。但是在2.3.6的星系gio上却没有......

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

这可能有助于您尝试使用Manifest

  <activity
            android:name=".YourActivity"
           android:windowSoftInputMode="stateHidden"> </activity>