Manish Kumar Manish Kumar - 5 months ago 19
Android Question

Trying Get Floating-EditText Children of a ViewGroup

I am trying to get Floating EditText from viewgroup (LinearLayout). Simple EditText Working fine but unable to get with it.

here is my code:

XML code:


<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_name"
android:inputType="textPersonName"
android:maxLines="1"
android:singleLine="true" />

</android.support.design.widget.TextInputLayout>


Java code:

for (int i = 0; i < layout.getChildCount(); i++) {

View v = layout.getChildAt(i);

if (v instanceof EditText) {

EditText editText = (EditText) v;

if (editText.getInputType() == InputType.TYPE_TEXT_VARIATION_PERSON_NAME + 1) {

isValid = validateName(et_name);

if (!isValid) {

break;
}

}


This ( android.support.design.widget.TextInputLayout ) is come between LinearLayout and EditText and i have no idea how to resolve it.

Thanks in advance

Answer

This should work:

if (v instanceof TextInputLayout) {
    EditText editText = (EditText) v.getChildAt(0);

But you should probably add some more checks to be sure you don't run into exceptions.

Comments