我需要在我的android活动中创建一个动态的单选按钮列表。每个按钮都包含一个文本标签和两个动作按钮,如:
但由于RG_list是垂直的(因为我希望所有按钮都是单独的行),它看起来像是:
这是我的代码:
RG_list = new RadioGroup(this); //create the RadioGroup
RG_list.setOrientation(RadioGroup.VERTICAL);
for ( String text: texts)
{
RadioButton RB_SingelBackupName = new RadioButton(this);
RB_SingelBackupName.setText(text);
RB_SingelBackupName.setButtonDrawable(new StateListDrawable());
RB_SingelBackupName.setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.btn_radio, 0);
RG_list.addView(RB_SingelBackupName);
// add delete button
ImageButton button_del = CreateImageButton( this, button_del); // Inner function
button_del.setOnClickListener(new View.OnClickListener() {
/* .... */
} });
RG_list.addView(button_del);
// add share button
ImageButton button_share = CreateImageButton( this, button_share ); // Inner function
button_share .setOnClickListener(new View.OnClickListener() {
/* .... */
} });
RG_list.addView(button_share);
}