skip to Main Content

I want to add a clear function to a button.
I have written this code:

clear.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            name.setHint("Enter name");
            mail.setHint("Enter mail");
            num.setHint("Enter num");
        }
    });

It works when the field is empty but does not if the field has content in it.

Thank you for your time.
It’s not a TextInputLayout. Works well with EditText.setText .

2

Answers


  1. The hint will not show when there is text inside a text field. You can clear text like below:

    clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
    
                name.setHint("Enter name");
                name.setText("");
    
                mail.setHint("Enter mail");
                mail.setText("");
    
                num.setHint("Enter num");
                num.setText("");
            }
        });
    
    Login or Signup to reply.
  2. The hint will only show when the content is empty. So you may clear your content and set hint at the same time.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search