Cursor position and empty EditText

Put your problem here if it does not fit any of the other categories.

Cursor position and empty EditText

Postby Derek5432 » Thu Mar 12, 2009 1:53 am to Android development, trying to implement my first app, a tip calculator, and having some issues.

First of all, in my EditText fields, the cursor defaults to the left of whatever text is entered. I have been unable to find any resource that indicates how to orient the cursor relative to the entered text. Alternatively, I wouldn't mind hiding the cursor. Could someone indicate how to handle either of these things?

Secondly, the app is crashing ("application has quit unexpectedly") if I try to use .getText() on an EditText object which does not have any text entered. What is the safe method for checking whether or not an EditText object contains text?

Junior Developer
Junior Developer
Posts: 15
Joined: Thu Mar 12, 2009 1:42 am


Postby MrSnowflake » Thu Mar 12, 2009 8:40 pm

1) Use EditText.setSelection().
2) When you get "application has ..." LOOK IN YOUR LOG! If you get an NullPointerException when calling EditText.getText() your edittext referene probably is null. If you didn't enter any text, the EditText.getText() would still return an object!
User avatar
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium


Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 5 guests