Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove cursor from editText [duplicate]

Tags:

android

Possible Duplicate:
Disable EditText blinking cursor

I have 2 editText fields in my activity with some text in it:

EditText nameText=(EditText) findViewById(R.id.update_name_text);
nameText.setText(Info.getName());

EditText phone=(EditText) findViewById(R.id.phone_number);
phone.setText(Info.getPhoneNo());

When I run the app on my device and tap on the nameText field, a cursor and a keyboard appear. However, when I hide the keyboard, the keyboard goes away but the cursor stays. How can I make the cursor invisible as well.

When I press enter from nameText, the cursor goes to the phone field and the keyboard is still visible.This is fine. But when I hide the keyboard or press enter from the phone field, the keyboard disappears but the cursor stays.

Is there any way (other than using setOnEditorActionListener) to make the cursor invisible as well in the above situations?

like image 655
Ankush Avatar asked Oct 23 '12 11:10

Ankush


3 Answers

to remove the cursor from edittext you need to set

nameText.setFocusable(false);

and to visible cursor set

nameText.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                nameText.setFocusableInTouchMode(true);

                return false;
            }
});

will show the cursor in edittext...

like image 101
Sumant Avatar answered Nov 15 '22 06:11

Sumant


android:cursorVisible in XML, or setCursorVisible() in code to hide/show the cursor, and you can use the method explained here to determine when the keyboard has appeared & disappeared.

like image 33
Todd Sjolander Avatar answered Nov 15 '22 05:11

Todd Sjolander


In Xml file You can see the <requestFocus> attribute has been automatically added for the EditText.

So whenever the activity starts , your EditText receives the focus.

So remove it first and try...

UpDated Answer:

If you dont want to edit the nameText field

You can use

nameText.setEnabled(false);

And also If u wants to Edit it some case,

You can do,

nameText.setEnabled(true);

Still you can update the nameText field by programatically,

for Example , using nameText.setText(Info.getname());

If you want the user to modifications on the visible text, then you can make

nameText.setEnabled(true);

It will works as like you expects.

like image 1
Kartihkraj Duraisamy Avatar answered Nov 15 '22 06:11

Kartihkraj Duraisamy