Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable keyboard on EditText

I'm doing a calculator. So I made my own Buttons with numbers and functions. The expression that has to be calculated, is in an EditText, because I want users can add numbers or functions also in the middle of the expression, so with the EditText I have the cursor. But I want to disable the Keyboard when users click on the EditText. I found this example that it's ok for Android 2.3, but with ICS disable the Keyboard and also the cursor.

public class NoImeEditText extends EditText {     public NoImeEditText(Context context, AttributeSet attrs) {        super(context, attrs);         }        @Override          public boolean onCheckIsTextEditor() {           return false;         }          } 

And then I use this NoImeEditText in my XML file

<com.my.package.NoImeEditText       android:id="@+id/etMy"  ....   /> 

How I can make compatible this EditText with ICS??? Thanks.

like image 645
Ferox Avatar asked May 17 '12 13:05

Ferox


People also ask

How to disable keyboard in EditText in Android?

setShowSoftInputOnFocus(false); to disable the software keyboard showing when the EditText is touched. the hideKeyboard(this); call in OnCreate to forcible hide the software keyboard.


1 Answers

Below code is both for API >= 11 and API < 11. Cursor is still available.

/**  * Disable soft keyboard from appearing, use in conjunction with android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"  * @param editText  */ public static void disableSoftInputFromAppearing(EditText editText) {     if (Build.VERSION.SDK_INT >= 11) {         editText.setRawInputType(InputType.TYPE_CLASS_TEXT);         editText.setTextIsSelectable(true);     } else {         editText.setRawInputType(InputType.TYPE_NULL);         editText.setFocusable(true);     } } 
like image 161
Oleksii Malovanyi Avatar answered Oct 04 '22 17:10

Oleksii Malovanyi