我想创建一个包含许多字段的行,如下所示:
Semper que eu clicar em "Add line fields" deve-se criar uma linha abaixo da outra com os 3 campos。
目前我的代码只插入一个EditText。代码:
final List<EditText> newFields = new ArrayList<EditText>();
final LinearLayout ll = (LinearLayout)findViewById(R.id.llAddNewFields);
Button btnCreateField = (Button)findViewById(R.id.btCreateField);
btnCreateField.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
MY_COUNT++;
EditText et = CriaeditText(String.valueOf(MY_COUNT));
newFields.add(et);
ll.addView(telefones.get(newFields.size()-1), new ViewGroup.LayoutParams(300,LayoutParams.WRAP_CONTENT));
}
});
方法创建EditText:
private EditText CriaeditText(String hint) {
EditText editText = new EditText(this);
editText.setId(Integer.valueOf(hint));
editText.setHint(hint);
editText.setTag(hint);
return editText;
}
只获取一个EditText的值:
private List getValuesDynamicField(LinearLayout l, List<EditText> li){
String[] arrValues = null;
List data = new ArrayList<String>();
for (int i = 0; i < l.getChildCount(); i++)
{
if (l.getChildAt(i).getVisibility() != View.GONE)
{
String p = li.get(i).getText().toString();
if (!p.equals(""))
{
data.add(p);
}
}
}
return data;
}
如何调整我的代码以根据需要插入 3 个字段?