Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

programmatically set edit text hint in android?

is there a way to set the text hint displayed inside of an android edittext with java? I would like for my app to be able to display different things in the edittext at different times, thanks in advance

like image 306
Edmund Rojas Avatar asked Feb 05 '12 21:02

Edmund Rojas


2 Answers

Did you try the setHint?

myTextView.setHint("My conditional hint"); 

Hope it helps..

like image 143
Orkun Ozen Avatar answered Oct 05 '22 15:10

Orkun Ozen


If you are using simple Editext without TextInputLayout :

EditText etUsername; etUsername = (EditText) findViewById(R.id.etUsername); etUsername.setHint("Your Hint"); 

If you are using Editext within TextInputLayout then you need to change property of TextInputLayout not Edittext:

TextInputLayout layoutUser; layoutUser = (TextInputLayout) findViewById(R.id.inputLayoutUname); layoutUser.setHint(getResources().getString(R.string.hintFaculty)); 
like image 21
M.Usman Avatar answered Oct 05 '22 13:10

M.Usman