0
我使用搜索欄對我的應用程序的Soundpool音量控制,我用PopupWindow的搜索條,一切工作正常,除了,每當我更改或暫停我的活動,我再次打開搜索條popupwindow,搜索條無我上次保存的價值越長。但它總是返回到它的默認值100%,甚至我用SharedPreferences什麼效果很好,但只有當我不離開當前活動。Android的搜索條進度不更新
public class ActivityMain extends Activity implements OnTouchListener, OnMenuItemClickListener {
SoundManager snd;
OnSeekBarChangeListener barChange1;
private int soundID;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main_activity);
}
public void onRestart() {
super.onRestart();
}
public void onResume() {
super.onResume();
final Button btnOpenPopup = (Button)findViewById(R.id.button6);
btnOpenPopup.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
barChange1 = new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
SharedPreferences prefs = getBaseContext().getSharedPreferences("mySharedPrefsFilename1", Context.MODE_PRIVATE);
prefs.edit().putInt("seekBarValue", seekBar.getProgress()).commit();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) { }
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
snd.setVolume((float)progress/100.0f);
}
};
SeekBar volbar1 = (SeekBar)popupView.findViewById(R.id.VolBar1);
volbar1.setMax(100);
int value = 0;
SharedPreferences prefs = getBaseContext().getSharedPreferences("mySharedPrefsFilename1", Context.MODE_PRIVATE);
value = prefs.getInt("seekBarValue", 100);
volbar1.setProgress(value);
volbar1.setOnSeekBarChangeListener(barChange1);
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btnOpenPopup, 60, 20);
}});
{
}
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
snd = new SoundManager(getApplicationContext());
soundID = snd.load(R.raw.sound_1);
ImageView img01 = (ImageView) findViewById(R.id.imageView11);
img01.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
}
snd.play(soundID);
return false;
}
});
}
@Override
public boolean onMenuItemClick(MenuItem item) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
}
@Override
protected void onPause() {
super.onPause();
snd.unloadAll();
}
}
嗨,我嘗試,但它使我的應用程序崩潰..必須測試更多的,也許是我做錯了什麼.. – Blackstarguy
volbar1很可能無法初始化爲此volbar1 =(搜索欄)popupView.findViewById(R.id .VolB) –
這就奇怪了,其實,搜索欄的作品,因爲它應該但從設備返回音量總是默認爲100%,如果我暫停或更改活動.. – Blackstarguy