均衡器 getBandLevel(i) returns 值 0
Equalizer getBandLevel(i) returns value 0
我正在循环我所有的预设,然后想使用它们。
现在,我调用的第一个 getBandLevel
方法返回一个可接受的值,但循环中的所有其他方法调用 returns me 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,并且它们dont.They 设置正确
代码:
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) {
}
});
}
您 SeekBar
的 SeekBar.OnSeekBarChangeListener
正在更改预设值。
在for循环中设置OnSeekBarChangeListener
,去掉前面的:
SeekBar seekbar= (SeekBar)findViewById((short)x);
seekbar.setOnSeekBarChangeListener(null);
seekbar.setProgress(m_equalizer.getBandLevel((short) x) - lowerEqualizerBandLevel );
seekbar.setOnSeekBarChangeListener(yourListenerHere);
我正在循环我所有的预设,然后想使用它们。
现在,我调用的第一个 getBandLevel
方法返回一个可接受的值,但循环中的所有其他方法调用 returns me 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,并且它们dont.They 设置正确
代码:
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) {
}
});
}
您 SeekBar
的 SeekBar.OnSeekBarChangeListener
正在更改预设值。
在for循环中设置OnSeekBarChangeListener
,去掉前面的:
SeekBar seekbar= (SeekBar)findViewById((short)x);
seekbar.setOnSeekBarChangeListener(null);
seekbar.setProgress(m_equalizer.getBandLevel((short) x) - lowerEqualizerBandLevel );
seekbar.setOnSeekBarChangeListener(yourListenerHere);