gkotla gkotla - 3 months ago 18
Android Question

how to put hint to edittext

I have two edittext input box. First one is for username and the second one is for password. I want put hint on the inputbox. I have wrote hint with settex() method. In addition, I have wrote

in onclick(view v)

caseR.id.editText_1:
text1.setText("");
break;

in oncreate

text1 = findViewById(R.id.editText_1);
text1.setText("username");


whenever I have click on the input box, hint should dissappear. But, hint is not dissappeared. Now, is the way I am doing wrong? Or I have missed something?

Answer

Use

text1.setHint("MyHintString");

instead. setHint() provides the hint that disappears when the user types something. You can also use a String resource ID or an xml based approach, but in your case, using the String method will suffice.

Only use setText() when you want to put text in the EditText that the user can modify.

Comments