I have an EditText in my application which is to only receive inputs from buttons I have placed on the screen.
To avoid the soft keyboard appearing I have a customised EditText class as follows:
public class CustomEditText extends EditText {
public CustomEditText(Context context) {
super(context);
}
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
// Disables Keyboard;
public boolean onCheckIsTextEditor() {
return false;
}
}
This successfully stops the keyboard from appearing, however in ICS this approach also stops the Cursor from appearing.
setCursorVisible(true)
does not have any effect.
I've tried alternate methods of keeping the soft keyboard hidden, such as using android:editable="false"
and .setKeyListener(null);
but none of these solutions have ever worked in my tests. The keyboard always appears.
So, is there a way to return the cursor in ICS, while keeping the onCheckIsTextEditor override as it is?
why don't you try to disable soft key-pad like this
//text field for input sequrity pin
txtPin=(EditText) findViewById(R.id.txtpin);
txtPin.setInputType(
InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_VARIATION_PASSWORD);
txtPin.setSelection(txtPin.getText().length());
txtPin.setTextSize(22);
txtPin.setSingleLine(true);
//disable keypad
txtPin.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
int inType = txtPin.getInputType(); // backup the input type
txtPin.setInputType(InputType.TYPE_NULL); // disable soft input
txtPin.onTouchEvent(event); // call native handler
txtPin.setInputType(inType); // restore input type
return true; // consume touch even
}
});
and for this EditText Field
<EditText android:layout_width="wrap_content"
android:id="@+id/txtpin"
android:maxLength="4"
android:layout_height="37dp"
android:gravity="center_horizontal"
android:longClickable="false"
android:padding="2dp"
android:inputType="textPassword|number"
android:password="true"
android:background="@drawable/edittext_shadow"
android:layout_weight="0.98"
android:layout_marginLeft="15dp">
<requestFocus></requestFocus>
</EditText>
this is working fine with me for input security PIN with cursor.
i am taking input from button not keypad.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With