我已经创建了动态视图。该视图包含两个edittext和一个广播组。当我点击添加按钮时,视图被添加到布局。现在我感到困惑,如何从这些类型的动态视图中获取值。我试过了,但它不起作用。当我添加两个或多个视图时,循环没有找到下一个视图值。我想将该值添加到ArrayList。这是代码:如何从动态编辑文本和广播组中获取值?
私人无效addDynamicViews(){
EditText name = new EditText(this);
EditText mobile = new EditText(this);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
p.setMargins(10, 10, 5, 5);
name.setLayoutParams(p);
name.setBackgroundResource(R.drawable.edittext_box);
name.setHint("Enter Name");
studentslayout.addView(name);
mobile.setLayoutParams(p);
mobile.setBackgroundResource(R.drawable.edittext_box);
mobile.setHint("Enter Mobile No");
studentslayout.addView(mobile);
/* radioGroup - Radio Group
maleButton,femaleButton - Radio Buttons
studentslayout - Linear Layout */
radioGroup = new RadioGroup(this);
radioGroup.setOrientation(RadioGroup.VERTICAL);
maleButton = new RadioButton(this);
maleButton.setText("Male");
radioGroup.addView(maleButton);
femaleButton = new RadioButton(this);
radioGroup.addView(femaleButton);
femaleButton.setText("Female");
studentslayout.addView(radioGroup);
}
如何采取一切动态的EditText和无线电集团的价值观? 我试过这段代码但不幸的是它停了。
@Override
public void onClick(View v) {
String[] array = new String[studentslayout.getChildCount()];
int count = studentslayout.getChildCount();
for (int i=0; i < studentslayout.getChildCount(); i++){
editText = (EditText)studentslayout.getChildAt(i);
array[i] = editText.getText().toString();
RadioButton radValues = (RadioButton) studentslayout.getChildAt(i);
array[i] = radValues.getText().toString();
}
}
对不起不工作 – suryac
如何获得兼具动感的EditText和无线电集团的价值观?请帮助我 – suryac