我正在尝试制作均衡器 RadioGroup。而且我想为预设动态添加单选按钮。
这是我的布局 XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/rgEqualizerPreset"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</RadioGroup>
</LinearLayout>
这是Java代码:
RadioGroup rgEqualizer;
List<RadioButton> radioButtonList;
MediaPlayer mPlayer;
Equalizer mEqualizer;
LinearLayout.LayoutParams layoutParams;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.equalizer);
rgEqualizer = (RadioGroup) findViewById(R.id.rgEqualizerPreset);
mPlayer = new MediaPlayer();
mEqualizer = new Equalizer(0, mPlayer.getAudioSessionId());
rgEqualizer = new RadioGroup(this);
radioButtonList = new ArrayList<RadioButton>();
fillRadioGroupWithRadioButtons();
rgEqualizer.setOnCheckedChangeListener(this);
}
private void fillRadioGroupWithRadioButtons() {
Short noPresets = mEqualizer.getNumberOfPresets();
int i = 0;
while (i < noPresets) {
RadioButton rb = new RadioButton(this);
rb.setText(mEqualizer.getPresetName((short) i));
layoutParams = new RadioGroup.LayoutParams(
RadioGroup.LayoutParams.FILL_PARENT,
RadioGroup.LayoutParams.FILL_PARENT);
rgEqualizer.addView(rb, layoutParams);
i++;
}
}
@Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
}
当此活动打开时,仅显示空白布局屏幕。我错过了什么?
谢谢