I need a reset button that reset all the editText boxes on click to the initial state. at the moment i have this:
main_xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ClearButton"
android:id="@+id/ClearButton"
android:onClick="clear"/>
java
public void clear(View v) {
TextBox1.setText("0.0");
TextBox2.setText("0.0");
}
i am not very happy with this reset because i have on startup 0.0 in the editText boxes anyway. i would like to implement the reset somewhere here:
input3 = String.valueOf(TextBox1.getText());
flowRate.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if ((hasFocus)&&(input3.equals("0.0") || input3.equals(""))) {
TextBox1.setText("");
}
input3 = (String.valueOf(TextBox1.getText()));
if ((!hasFocus) && (input3.equals(""))){
TextBox1.setText("0.0");
}
}
});
// remove on touch the value entries in the Flow rate field to start calculation
// if no value is entered the field will return to his normal state (0.0)
input2 = String.valueOf(TextBox2.getText());
TextBox2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if ((hasFocus)&&(input2.equals("0.0") || input2.equals(""))) {
TextBox2.setText("");
}
input2 = (String.valueOf(TextBox2.getText()));
if ((!hasFocus) && (input2.equals(""))){
TextBox2.setText("0.0");
}
}
});
at the moment when i reset and my focus is on a editText Box i have to delete the 0.0 first before i can write a value in the box. i would like on reset that the focus come out the editText box and everything is on the initial state.