您好,我正在膨胀 xml 文件,例如..
List<EditText> allEds3 = new ArrayList<EditText>();
LayoutInflater inflater = inflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int hh1 = 57; hh1 <= 76; hh1++) {
try {
View view = inflater.inflate(R.layout.form6, null);
form6_linear.addView(view);
lbl1 = (TextView) view.findViewById(R.id.lbl1);
lbl2 = (TextView) view.findViewById(R.id.lbl2);
txt1 = (TextView) view.findViewById(R.id.txt1);
txt1.setId(hh1);
txt1.setText(txt_array.get(hh1));
txt1.setOnClickListener(onclicklistener);
_txt2 = (EditText) view.findViewById(R.id.txt2);
lbl1.setText(lbl_array.get(hh1));
lbl2.setText(lbl_array.get(hh1 + 1));
_txt2.setText(txt_array.get(hh1 + 1));
allEds3.add(_txt2);
hh1++;
nn1++;
} catch (Exception e) {
// TODO: handle exception
}
}
现在我的主 xml 文件中有一个按钮,单击该按钮我必须获取上面这个_txt2的所有值。
请帮忙。
编辑:
List<EditText> allEds3 = new ArrayList<EditText>();
LayoutInflater inflater = inflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int hh1 = 57; hh1 <= 76; hh1++) {
try {
View view = inflater.inflate(R.layout.form6, null);
form6_linear.addView(view);
lbl1 = (TextView) view.findViewById(R.id.lbl1);
lbl2 = (TextView) view.findViewById(R.id.lbl2);
txt1 = (TextView) view.findViewById(R.id.txt1);
txt1.setId(hh1);
txt1.setText(txt_array.get(hh1));
txt1.setOnClickListener(onclicklistener);
_txt2 = (EditText) view.findViewById(R.id.txt2);
lbl1.setText(lbl_array.get(hh1));
lbl2.setText(lbl_array.get(hh1 + 1));
_txt2.setText(txt_array.get(hh1 + 1));
allEds3.add(_txt2);
hh1++;
nn1++;
} catch (Exception e) {
// TODO: handle exception
}
}
点击()
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_continue1:
final String[] strings2 = new String[allEds3.size()];
for (int i = 0; i < allEds3.size(); i++) {
strings2[i] = allEds3.get(i).getText().toString();
}
int ii = 0;
for (int db = 57; db <= 76; db++) {
try {
j.remove(txt_array.get(db));
j.put(txt_array.get(db), strings2[ii]);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ii++;
}
}
}
错误:- ArrayIndexOutOfBounds 在
j.put(txt_array.get(db), strings2[ii]);