How do I clear the data which is given to an EditText dynamically when clicking the button? How do I write the code? What function or method do I use?
You can use function
myEditText.setText("");
Try
public void clear(View v) {
edittext.setText("");
}
Where clear
is registered as onclick handler for the button in the layout file like this
<ImageButton android:id="@+id/ClearButton"
android:text="@string/ClearButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="clear" <<<--------here
android:src="@drawable/clear"
/>
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