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?

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
Post a Comment