我已經創建了動態收音機組,其中每個組都有三個單選按鈕,所以選中的更改監聽器如何獲得收音機組中選中的單選按鈕的ID .....謝謝提前..如何獲得收音機組的選中的收音機ID
public class Rate_me_up extends Activity implements OnClickListener,
OnCheckedChangeListener {
LinearLayout layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.rate_me_up);
layout = (LinearLayout) findViewById(R.id.linear);
Button btnp = (Button) findViewById(R.id.buttonp);
btnp.setOnClickListener(this);
}
@Override
public void onClick(View v) {
RadioGroup radioGroup = new RadioGroup(Rate_me_up.this);
radioGroup.setOrientation(1);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
layout.addView(radioGroup, p);
RadioButton radioButtonView = new RadioButton(Rate_me_up.this);
radioButtonView.setText("RadioButton");
radioButtonView.setChecked(false);
radioGroup.addView(radioButtonView, p);
RadioButton radioButtonView2 = new RadioButton(Rate_me_up.this);
radioButtonView2.setText("RadioButton2");
radioButtonView2.setChecked(false);
radioGroup.addView(radioButtonView2, p);
RadioButton radioButtonView3 = new RadioButton(Rate_me_up.this);
radioButtonView3.setText("RadioButton2");
radioGroup.addView(radioButtonView3, p);
radioButtonView3.setChecked(false);
radioGroup.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
}
}
首先通過setId()方法設置'RadioButton'的id。 –
這樣做之後...如何獲得ID ... – bhavdip
'onCheckedChanged'中的'checkedId'會返回您選中的'RadioButton'的ID。 – Apoorv