在EditText数组上禁用Android键盘

在EditText数组上禁用Android键盘,android,android-layout,android-intent,android-widget,Android,Android Layout,Android Intent,Android Widget,我有一个EditText数组,我想禁用每次单击它们时出现的标准键盘Android 以下是我正在使用的零件代码: InputMethodManager imm = (InputMethodManager)getSystemService( Context.INPUT_METHOD_SERVICE); for (i=0;i<dim*dim;i++){ imm.hideSoftInputFromWindow(value[i].getWindowTok

我有一个EditText数组,我想禁用每次单击它们时出现的标准键盘Android

以下是我正在使用的零件代码:

InputMethodManager imm = (InputMethodManager)getSystemService(
              Context.INPUT_METHOD_SERVICE);
for (i=0;i<dim*dim;i++){

        imm.hideSoftInputFromWindow(value[i].getWindowToken(), 0);
        value[i].setOnTouchListener(this);
        value[i].setOnClickListener(this);
        value[i].setOnFocusChangeListener(this);


    }
在我的主要课程OnCreate中:

for (i=0;i<dim*dim;i++){

((KeyboardControlEditText) value[i]).setShowKeyboard(false);
value[i].setOnTouchListener(this);
value[i].setOnClickListener(this);


}

for(i=0;i您需要为此创建自己的
EditText
类。然后,覆盖默认值并返回
false

public class NoKeyboardEditText extends EditText {
    // This constructor has to be overriden
    public NoKeyboardEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    // Now tell the VM that we are not a text editor
    @Override
    public boolean onCheckIsTextEditor() {
        return false;
    }
}
确保用正确的名称替换新的
EditText
。例如,如果您的包是
com.example.widget
,则您希望使用

如果您需要动态,您甚至可以获得更高的想象力:

public class KeyboardControlEditText extends EditText {
    private boolean mShowKeyboard = false;

    public void setShowKeyboard(boolean value) {
        mShowKeyboard = value;
    }

    // This constructor has to be overriden
    public KeyboardControlEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    // Now tell the VM whether or not we are a text editor
    @Override
    public boolean onCheckIsTextEditor() {
        return mShowKeyboard;
    }
}

这样,您就可以调用
((KeyboardControlEditText)myEditText)
在运行时更改它。

也许我做错了什么,但我仍然看到Android中的键盘。您更改了XML文件以反映新类吗?我在Manifest中添加了新类。我编辑了我的帖子,用我现在在我的主类中使用的代码行,试图使用他的建议。当我说“XML”时,我指的是你的布局文件。你知道,你在哪里设置了
@imrhung,我不知道。
public class KeyboardControlEditText extends EditText {
    private boolean mShowKeyboard = false;

    public void setShowKeyboard(boolean value) {
        mShowKeyboard = value;
    }

    // This constructor has to be overriden
    public KeyboardControlEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    // Now tell the VM whether or not we are a text editor
    @Override
    public boolean onCheckIsTextEditor() {
        return mShowKeyboard;
    }
}