0

So basically, if the user doesn't use this edittext, then the default value stays at zero. But if they want to type something in, the zero disappears as soon as they start typing.

I have tried using:

android:hint"0"

But that doesn't affect the default value.

And when I use:

android:text"0"

That sets the value of the editText as 0, but you have to manually delete the zero and then start typing in the number that they want to enter.

2 Answers2

2

To achieve that I would do this: Keep the hint attribute for ui and maintain the default value programmatically:

if(editText.getText().toString().isEmpty())
    //set the value as zero
Ratul Doley
  • 499
  • 1
  • 6
  • 12
1

useandroid:hint"0"and do these below in your java code

private String editTextValue;
private EditText mEditText;
private static final String DEFAULT_VALUE = "0";

if(TextUtils.isEmpty(mEditText.getText())){
   editTextValue = DEFAULT_VALUE;
} else {
   editTextValue  = editText.getText();
}
Wooby
  • 216
  • 2
  • 10