开发者

How to make EditText erase evertime a button is clicked

开发者 https://www.devze.com 2023-03-14 00:59 出处:网络
Okay i have a edit text box that takes user input. Every ti开发者_如何学JAVAme the user clicks the button i would like for the text that the user typed to be gone. As of now everytime the button is cl

Okay i have a edit text box that takes user input. Every ti开发者_如何学JAVAme the user clicks the button i would like for the text that the user typed to be gone. As of now everytime the button is clicked the text remains in the edittext. I would like the text to be erased by default without having to create a instance of EditText everytime

Thanks guys if you can help!


Use setText():

mEditText.setText("");


after your setContentView:

final EditText yourEditText= (EditText)findViewById(R.id.yourIDEditText);
    yourEditText.setOnClickListener(new View.OnClickListener() 
    {
           @Override
           public void onClick(View v) 
           {
               yourEditText.setText("");
           }

 });

With this, every time the user clicks all content is cleaned.

0

精彩评论

暂无评论...
验证码 换一张
取 消