Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between hint in TextInputLayout vs hint in TextInputEditText

I found crash in crashlog of "NullPointerException: Attempt to invoke virtual method 'void android.view.View.getBoundsOnScreen(android.graphics.Rect)' on a null object reference" and I verified some stackoverflow suggestions for this crash. I found below link suggest to use hint in TextInputLayout instead of TextInputEditText, so I want to know what makes it different?

Below link suggests to use hint in TextInputLayout: SO Google shows to use hint in TextInputEditText: Google_Recommendation

I tried hint in both place of TextInputLayout and TextInputEditText. Hint worked well in both place similarly.

I would like to know what is the difference between both method and which one is more appropriate to use.

like image 237
NanPd Avatar asked Oct 18 '25 22:10

NanPd


1 Answers

In design support library TextInputLayout was introduced to display the floating label on EditText or TextInputEditText . The EditText or TextInputEditText has to be wrapped by TextInputLayout in order to display the floating label.

Rule of Thumb : TextInputLayout should wrap TextInputEditText

where should you place hint

according to the official documentation

The hint should be set on the TextInputLayout, rather than the EditText. If a hint is specified on the child EditText in XML, the TextInputLayout might still work correctly; TextInputLayout will use the EditText's hint as its floating label. However, future calls to modify the hint will not update TextInputLayout's hint. To avoid unintended behavior, call setHint(CharSequence) and getHint() on TextInputLayout, instead of on EditText.

Note that TextInputEditText is special sub-class of EditText designed for use as a child of TextInputLayout.

hope it's helpful

like image 50
ismail alaoui Avatar answered Oct 20 '25 13:10

ismail alaoui