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