0
,同時選擇第一個單選按鈕,但它沒有顯示它的選中狀態。但是當我選擇其他選項時,如果我先選擇它,則顯示其選中狀態。動態地做了單選按鈕,但有時第一個單選按鈕無法選擇
代碼: -
private void Displayradiobutton(String hatchfetchnumber) {
DBAdapter db = new DBAdapter(getApplicationContext());
Log.i("test", "SETTING ADAPTER FOR DISPLAYRADIOBUTTON()");
Cursor cr;
cr = db.gethatchno(hatchfetchnumber);
Log.i("test", "GET DATA FROM GETHATCHNO" + cr);
cr.moveToFirst();
selecthatch = cr.getInt(0);
Log.i("test", "Step 2");
if (selecthatch >= 12) {
down.setVisibility(View.VISIBLE);
} else {
down.setVisibility(View.INVISIBLE);
}
errortext.setVisibility(View.VISIBLE);
radiogroup.removeAllViews();
for (int i = 1; i <= selecthatch; i++) {
RadioButton rdbtn = new RadioButton(this);
rdbtn.setId(i);
rdbtn.setPadding(15, 7, 15, 7);
rdbtn.setTextSize(20);
rdbtn.setText("Hatch " + i);
radiogroup.addView(rdbtn);
text.setEnabled(true);
if (selecthatch == 1) {
rdbtn.setChecked(true);
flag = 1;
} else {
flag = 0;
}
}
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
flag = 1;
errortext.setVisibility(View.INVISIBLE);
// selectedHatch = (RadioButton) findViewById(checkedId);
}}