===============================================
LinearLayout.LayoutParams param4RdoGrp=new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
param4RdoGrp.setMargins(16, 0, 0, 0);
radioGroup=new RadioGroup(activityContex);
radioGroup.setOrientation(RadioGroup.HORIZONTAL);
radioGroup.setLayoutParams(param4RdoGrp);
currentView.addView(radioGroup);
int checkId=-1;
for(int i=0;i<options.length;i++){
RadioButton rdoBtn=new RadioButton(activityContex);
rdoBtn.setText(options[i]);
radioGroup.addView(rdoBtn); <--先加入有了id再決定怎麼做
if(options[i].equals(selectedOption)){
// rdoBtn.setChecked(true); <--這樣不行,會把radio button 卡住!!
checkId=rdoBtn.getId();
}
}
if(checkId!=-1){
radioGroup.check(checkId); <--這時才能設定check!!
}
=======================================
沒有留言:
張貼留言