我在对话框中呈现 TextView 和 Seekbar 时遇到了一个问题。
我正在从android 网站练习本教程
问题出在 for 循环中,TextView 和 SeekBar 应该被添加 5 次,并且应该显示在 Dialog 中。但只显示一个 TextView。
这是代码:
public void onCheckedChanged(RadioGroup rgroup, int rbutton) {
String eqSettingName = ((RadioButton) findViewById(rbutton)).getText()
.toString();
if (eqSettingName.equals("Custom")) {
Dialog dialog = new Dialog(this);
dialog.setTitle("Custom Equalizer");
LinearLayout LL = new LinearLayout(this);
short noOfBands = mEqualizer.getNumberOfBands();
final short minEQLevel = mEqualizer.getBandLevelRange()[0];
final short maxEQLevel = mEqualizer.getBandLevelRange()[1];
for (short i = 0; i < noOfBands; i++) {
short band = i;
TextView freqTV = new TextView(this);
freqTV.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
freqTV.setGravity(Gravity.CENTER_HORIZONTAL);
freqTV.setText((mEqualizer.getCenterFreq(band)) / 1000 + " Hz");
LL.addView(freqTV);
SeekBar bar = new SeekBar(this);
bar.setLayoutParams(layoutParams);
bar.setMax(maxEQLevel - minEQLevel);
bar.setProgress(mEqualizer.getBandLevel(band));
LL.addView(bar);
}
/*
LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.customseekbar,
(ViewGroup) findViewById(R.id.rlCustomEqualizerSeekBar));
*/
dialog.addContentView(LL, layoutParams);
dialog.show();
}
}