Android - Arreglo de EditText

 
Vista:
sin imagen de perfil

Arreglo de EditText

Publicado por Emilio (10 intervenciones) el 20/10/2017 20:27:22
Hola que tal?
tengo un problema y no se como resolverlo

en mi proyecto necesitan poner un botón que valla creando EditText hasta ahí no tengo problema pero de hay otro botón va a capturar los datos de todos los EditText es donde tengo problemas como capturo todos los datos de los EdtiText y los pongo en un ArrayList o List o String[] porfavor necesito su ayuda

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
 
import android.widget.LinearLayout;
import android.widget.TextView;
 
 
import com.fapv2.proto.fapv2.R;
 
 
public class RegistroMultiple extends Fragment{
 
    Button BTNA,BTNC;
    LinearLayout LLH;
    EditText TXTP;
    int CCIP;
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        final View rootView = inflater.inflate(R.layout.fragment_psicofisico_registrarmultiple, container, false);
 
        LLH=(LinearLayout) rootView.findViewById(R.id.LLH);
        BTNA=(Button) rootView.findViewById(R.id.BTNAC);
        BTNC=(Button) rootView.findViewById(R.id.BTNEV);
        TXTP=(EditText) rootView.findViewById(R.id.T0);
 
        CCIP=0;//Reinicia el contador a 0 cuando entra al fragmento
 
        BTNA.setOnClickListener(new View.OnClickListener() {
 
 
            @Override
            public void onClick(View v) {
 
                CCIP=CCIP+1;
 
 
                TextView lblcip=new TextView(getContext());
                EditText txtnu=new EditText(getContext());
                LinearLayout lin=new LinearLayout(getContext());
 
                //lblcip.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
                lblcip.setWidth(100);
                lblcip.setText("CIP");
                lblcip.setTextSize(18);
 
                //txtnu.setGravity(Gravity.CENTER_VERTICAL);
                txtnu.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
                txtnu.setWidth(250);
                txtnu.setId(CCIP);
                txtnu.setText("hola"+CCIP);
 
                lin.addView(lblcip);
                lin.addView(txtnu);
                LLH.addView(lin);
 
 
            }
        });
 
 
 
        BTNC.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TXTP.getText();
 
                for (int i=0;i<CCIP;i++){
                    //Aca es donde debe capturar los datos de los EditText
                }
            }
        });
 
 
 
        return rootView;
    }
}


el .xml es un fragmento


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.fapv2.proto.fapv2.PuntajePsicofisico$PlaceholderFragment">
 
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
 
 
        <LinearLayout
            android:id="@+id/LLH"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
 
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">
 
                <Button
                    android:id="@+id/BTNAC"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Agregar" />
 
                <Button
                    android:id="@+id/BTNEV"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Evaluar" />
            </LinearLayout>
 
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">
 
                <TextView
                    android:id="@+id/textView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="CIP"
                    android:textSize="18sp" />
 
                <EditText
                    android:id="@+id/T0"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:ems="10"
                    android:inputType="textPersonName" />
 
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>
 
</ScrollView>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Francisco
Val: 466
Oro
Ha mantenido su posición en Android (en relación al último mes)
Gráfica de Android

Arreglo de EditText

Publicado por Francisco (358 intervenciones) el 21/10/2017 23:41:58
Debes recorrer todos los elementos que hay en el linearLayout= LLH principal,porque el otro lo has creado dinamicamente


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
for (int index = 0; index <= LLH.getChildCount() ; index++) {
 
	// Aqui tienes otro layout dentreo de un layout
 
	LinearLayout hh =(LineraLayout)LLH.getChildAt(index);
 
	//Luego lo recorres y te apareceran los editText y recoges el valor 
 
 
	for (int index2 = 0; index2 <= hh.getChildCount(); index2++) {
 
		String valor= hh.getChildAt(index2).getText()
 
		//Aqui coges el valor y lo añades al array
	}
}



No lo he probado pero es algo asi,

Comenta si te ha servido para algo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Arreglo de EditText

Publicado por Emilio (10 intervenciones) el 23/10/2017 19:30:35
si me sirvió muchas gracias pero en

1
String valor= hh.getChildAt(index2).getText();


me sale un error de sintaxis dice que no de ser String un tipo View

lo resolví con esto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
for(int i=2;i<LLH.getChildCount();i++){
 
    LinearLayout hh=(LinearLayout) LLH.getChildAt(i);
 
    for(int j=0;j<hh.getChildCount();j++){
 
        View valor=hh.getChildAt(j);
        if(valor.getId()!=-1) {
 
            EditText rs=(EditText) valor;
 
            Toast.makeText(getContext(), "se canturo los ET " + rs.getText(), Toast.LENGTH_SHORT).show();
 
        }
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Francisco
Val: 466
Oro
Ha mantenido su posición en Android (en relación al último mes)
Gráfica de Android

Arreglo de EditText

Publicado por Francisco (358 intervenciones) el 23/10/2017 19:35:33
Prueba esto a ver.

String valor= hh.getChildAt(index2).getText().toString();
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar