Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the edittext when onclick on Button

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?

like image 271
Ratna Yellapragadaa Avatar asked Jan 06 '12 13:01

Ratna Yellapragadaa


2 Answers

You can use function

myEditText.setText("");
like image 162
nisha.113a5 Avatar answered Sep 23 '22 06:09

nisha.113a5


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"
    />
like image 31
Heiko Rupp Avatar answered Sep 22 '22 06:09

Heiko Rupp