To clear EditText when a Button is Clicked

Well we usually don’t have a cross sign in an android to delete the mistype keyword when usually we type fast or we are in rush. But In our Android App we definitely can have a customized button which does the task for us.

My Assumption:
1. I have a EditText called firstName, where i mistype and want to delete it at once.
2. I create a clear button with its ID clearsearchSubmit.
3. I set OnClickListener in the clear Button.
4. So when Button is Clicked, it Checks the ID if it matches then we set the text of firstName as null i.e (“”)

firstName = (EditText) findViewById(R.id.firstName);
clear = (Button) findViewById(R.id.clearsearchSubmit);
clear.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {  

// TODO Auto-generated method stub  

if (v.getId() == R.id.clearsearchSubmit); firstName.setText(“”); } });


This will help to clear the wrong keywords that you have typed in so instead of pressing backspace again and again you can simply click the button to clear everything.It Worked For me. Hope It Helps! Cheers!!

Leave a Reply

Your email address will not be published. Required fields are marked *

*