"button2.setOnClickListener(radio_listener);"アンドロイドラジオグループの選択に基づいてどのようにラジオグループを動的に変更しますか
理由は、その自分自身を呼び出す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