android - TextInputLayout not showing when View added programmatically -


i noticed strange behaviour of textinputlayout:

when add following layout:

    <android.support.design.widget.textinputlayout         android:layout_width="match_parent"         android:layout_height="wrap_content">          <edittext             android:id="@+id/txtfirstname"             style="@style/edittextstyle"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:hint="in layout"             android:singleline="true" />     </android.support.design.widget.textinputlayout> 

everything works expected.

when inflate similar layout like:

    view v = layoutinflater.from(this).inflate(r.layout.edittext_w_surrounding_textinputlayout, null);     edittext edittext = (edittext) v.findviewbyid(r.id.edittext);     edittext.sethint("added programmatically");      viewgroup root = (viewgroup) findviewbyid(r.id.root);     root.addview(v); 

the textinputlayout doesn't appear , edittext behaves standard way.

any ideas reason be?

enter image description here

you should change hint, not on edittext, on textinputlayout. be:

textinputlayout v = (textinputlayout) layoutinflater.from(this).inflate(r.layout.edittext_w_surrounding_textinputlayout, null); v.sethint("added programmatically"); 

textinputlayout has it's own hint parameter , when inflating layout get's hint it's child edittext , set empty hint on it.

when want change hint programatically have call textinputlayout.sethint(string text) instead of changing edittext hint


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -