我循环播放所有预设,并希望在此之后使用它们。
现在,我调用的第一个getBandLevel
方法返回一个可接受的值,但循环中的所有其他方法调用都返回0.我在哪里可能出错?
这是我的循环代码:
m_equalizer.usePreset((short)position);
short numberFrequencyBands = .m_equalizer.getNumberOfBands();
final short lowerEqualizerBandLevel = m_equalizer.getBandLevelRange()[0];
for(short x=0;x<numberFrequencyBands;x++)
{
SeekBar seekbar= (SeekBar)findViewById((short)x);
seekbar.setProgress(m_equalizer.getBandLevel((short) x) - lowerEqualizerBandLevel ); //Here is getBandLevel returning me 0 after x is 1
}
编辑:我还检查了其他应用是否也提供了0而且他们没有。他们有正确的设置
代码:
public void equalizeSound()
{
ArrayList<String> equalizePresetNames = new ArrayList<String>();
ArrayAdapter<String> equalizerPresetSpinnerAdapter = new ArrayAdapter<String>(this,R.layout.custom_spinner_item_small,equalizePresetNames);
equalizerPresetSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner equalizerPresetSpinner = (Spinner)findViewById(R.id.spinner_presets_eq);
for(short i=0;i< m_equalizer.getNumberOfPresets();++i)
{
equalizePresetNames.add(m_equalizer.getPresetName(i));
}
equalizerPresetSpinner.setAdapter(equalizerPresetSpinnerAdapter);
equalizerPresetSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
m_equalizer.usePreset((short)position);
short numberFrequencyBands = m_equalizer.getNumberOfBands();
final short lowerEqualizerBandLevel = m_equalizer.getBandLevelRange()[0];
for(short x=0;x<numberFrequencyBands;x++)
{
SeekBar seekbar= (SeekBar)findViewById((short)x);
seekbar.setProgress(m_equalizer.getBandLevel((short) x) - lowerEqualizerBandLevel );
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
答案 0 :(得分:2)
SeekBar.OnSeekBarChangeListener
的{{1}}正在更改预设值。
在for循环中设置SeekBar
,删除前一个:
OnSeekBarChangeListener