Codes
Codes

Reputation: 225

How to set an EditText to empty with a number input type

I have tried

editText.setText(""); 

however I get an error saying "" is not a valid integer. I have also tryed changing the input type to text setting the text to "" than changing the input type back to numbers but I get the same error.

Upvotes: 0

Views: 4889

Answers (4)

Kirthiga
Kirthiga

Reputation: 291

Set the prperties in XML as

android:hint = ""

In Java

editText.setHint("");

Upvotes: 0

Tonithy
Tonithy

Reputation: 2290

Try this:

editText.setText("0", BufferType.EDITABLE); /*// May be unecessary... */
editText.getText().clear();

You may need to set the buffer type to BufferType.EDITABLE first...

Upvotes: 1

Stefano Munarini
Stefano Munarini

Reputation: 2717

In XML use properties

android:hint=""
android:inputType="number"

In code use

.setHint("");

Upvotes: 3

Silvano
Silvano

Reputation: 203

You can use an empty string value in res/values/string.xml, like --> < string name:"empty_string">< /string>

Upvotes: 0

Related Questions