1

I have a Button that, when click on it, displays 6 TextEdits. This happens trhough a inflated layout, that contains the TextEdits. That means, that everytime you click on the Button you get 6 new TextEdit. Now, how can i collect the Values of all of them?

Inflated Layout XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="368dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="8dp"
    android:orientation="horizontal">

<EditText
    android:id="@+id/nombrePuntaje"
    android:layout_width="54dp"
    android:layout_height="42dp"
    android:layout_weight="1"
    android:ems="10"
    android:inputType="textPersonName"
    android:hint="Nombre"
    />

    <EditText
        android:id="@+id/j1"
        android:layout_width="54dp"
        android:layout_height="42dp"
        android:layout_weight="1"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="00"
         />

    <EditText
        android:id="@+id/j2"
        android:layout_width="54dp"
        android:layout_height="42dp"
        android:layout_weight="1"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="00"
         />

    <EditText
        android:id="@+id/j3"
        android:layout_width="54dp"
        android:layout_height="42dp"
        android:layout_weight="1"
        android:ems="10"
        android:inputType="textPersonName"
        android:hint="00"
         />

    <EditText
        android:id="@+id/j4"
        android:layout_width="wrap_content"
        android:layout_height="42dp"
        android:layout_weight="1"
        android:ems="2"
        android:inputType="textPersonName"
        android:hint="00"
         />

    <EditText
        android:id="@+id/j5"
        android:layout_width="wrap_content"
        android:layout_height="42dp"
        android:layout_weight="1"
        android:ems="2"
        android:inputType="textPersonName"
        android:hint="00"
         />

Here int the activity, when inflates:

agregarPuntajes = (Button) findViewById(R.id.cargarPuntajes);
    agregarPuntajes.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //https://stackoverflow.com/questions/29673613/remove-and-add-layout-dynamically-by-click-button-in-android
            LayoutInflater ltInflater = getLayoutInflater();
            final LinearLayout subLayoutFields = (LinearLayout) findViewById(R.id.contenedorPuntajes);
            final View view1 = ltInflater.inflate(R.layout.puntos, subLayoutFields, true);
        }
    });

Thank you :)

rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38

1 Answers1

0

To gather all the edit texts

LinearLayout myLayout = get the layout of edit-texts

ArrayList<EditText> myEditTextList = new ArrayList<EditText>();

for( int i = 0; i < myLayout.getChildCount(); i++ )
  if( myLayout.getChildAt( i ) instanceof EditText )
myEditTextList.add( (EditText) myLayout.getChildAt( i ) );