Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Custom EditText not showing cursor in ICS

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?

like image 202
user1178196 Avatar asked Apr 02 '12 13:04

user1178196


1 Answers

why don't you try to disable soft key-pad like this

PINLockactivity.java

    //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

xml code is

<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.

like image 196
swiftBoy Avatar answered Nov 15 '22 19:11

swiftBoy