How to reset EditText after an action has been completed?
Asked Answered
C

5

10

I would like to reset my EditText back to an empty "space" or a "hint" after a button has pressed that would have completed an activity with input from the EditText field.

My adventure with android thus beckons.

Cheers. Thank you !!

 //************-------------------SEND SMS----------------*********//
    btnSendSMS = (Button)findViewById(R.id.sms);
    btnSendSMS.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            sendSMS(dispEd.getText().toString(),msgEd.getText().toString());
        }

        private void sendSMS(String phoneNumber, String msg) {
            // TODO Auto-generated method stub
            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(phoneNumber, null, msg, null, null);
        }
    });
}

<EditText 
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:id="@+id/edit"/>

<EditText 
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:id="@+id/msg"/>
Cherry answered 30/8, 2011 at 10:26 Comment(0)
S
25

you should try

editText.setText("");

Update: Try setting text as null

editText.setText(null);
Stringpiece answered 30/8, 2011 at 10:29 Comment(0)
H
7

try this:

EditText edit;
edit.setText(null);
Hexapod answered 30/8, 2011 at 10:29 Comment(0)
L
6

Use ediText.getText().clear();

It works like a charm for me.

Lyingin answered 24/3, 2015 at 4:59 Comment(1)
absolutely! fantasticSadiras
C
1

Maybe what you're really looking for is setting android:hint="text" on your edittext in the layout XML.

No extra code is required to achieve this behavior.

Curlpaper answered 22/12, 2015 at 12:36 Comment(0)
L
1

If u want clear the EditText use-

name.setText("");

or

name.setText(null);

If u wanna add Hint

name.setText(null);
name.setHint("Enter First Team Name");

Else if you have already added hint earlier than just use this and hint will be displayed-

name.setText(null);
Limy answered 25/9, 2016 at 4:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.