I've added multiple EditText and TextViews dynamically like:
final String[] meses = new String[]{"Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"};
for(int i=0; i<meses.length; i++){
LinearLayout layout = new LinearLayout(getContext());
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
TextView textview = new TextView(getContext());
ViewGroup.LayoutParams lparams = new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f);
textview.setLayoutParams(lparams);
textview.setText(meses[i]);
layout.addView(textview);
EditText ed = new EditText(getContext());
ed.setLayoutParams(lparams);
ed.setId(i);
layout.addView(ed);
llMes.addView(layout);
}
But now I need to retrieve the values of each EditText, how can I retrieve it, I have this:
for(int i=0; i < meses.length; i++){
EditText et = null;
et.getId();
pago = quotas - Integer.parseInt(et.getText().toString());
}
And also tried with findViewById(i) with for but also failed.
Thanks for helping me!
Add EditTexts to an ArrayList then retrieve it by index.