我正在使用搜索栏我想保存用户在搜索栏和搜索栏中所做的更改应该在下次打开应用程序时显示。我的代码是
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
start=-10; //you need to give starting value of SeekBar
end=10; //you need to give end value of SeekBar
start_pos=5; //you need to give starting position value of SeekBar
start_position=(int) (((start_pos-start)/(end-start))*100);
discrete=start_pos;
SeekBar seek=(SeekBar) findViewById(R.id.seekBar1);
seek.setProgress(start_position);
seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "discrete = "+String.valueOf(discrete), Toast.LENGTH_SHORT).show();
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
// To convert it as discrete value
float temp=progress;
float dis=end-start;
discrete=(start+((temp/100)*dis));
}
});
}
}
答案 0 :(得分:1)
检查此post - 并尝试了解如何优先保存数据。 然后在你的活动中
@Override
protected void onPause() {
super.onPause();
// save seekBarPgrogress to preference here.
}
@Override
protected void onResume() {
super.onResume();
// load seekBarPgrogress from preference here.
// and call seek.setProgress(position);
}
希望得到帮助
答案 1 :(得分:0)
将搜索栏进度保存到onPause中的共享首选项,并在onResume中设置共享首选项的搜索栏进度