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;
}
}
<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>
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
}
}
String valor= hh.getChildAt(index2).getText();
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();
}
}
}