我在“button2.setOnClickListener(radio_listener)”上得到一个错误;“android如何动态改变基于radiogroups选择的radiogroup
因为它内嵌在onclick监听器中调用自己,所以最近怎么样?
final RadioGroup rGroup3 = (RadioGroup) findViewById(R.id.radio_gcam);
OnClickListener radio_listener = new OnClickListener() {
public void onClick(View v) {
RadioButton button = (RadioButton) v;
no_of_gcams = 3;
gcam_names_array[0] = "Machine 1";
gcam_names_array[1] = "Machine 2";
gcam_names_array[2] = "Machine 3";
gcam_names_array[3] = "Machine 4";
for (int i = 0; i < no_of_gcams; i++)
{
RadioButton button2 = new RadioButton(ModbusDroid.this);
button2.setText(gcam_names_array[i]);
button2.setOnClickListener(radio_listener);
rGroup3.addView(button2);
}
}
};
if (no_of_gcams == 0)
{
RadioButton button1 = new RadioButton(this);
button1.setText("Setup a G-CAM");
button1.setOnClickListener(radio_listener);
rGroup3.addView(button1);}
干杯,简单但有效:) – Monkins1010