Seekbar想要保存进度[重复]
Posted
技术标签:
【中文标题】Seekbar想要保存进度[重复]【英文标题】:Seekbar want to save progress [duplicate] 【发布时间】:2013-03-31 21:05:50 【问题描述】:我正在使用搜索栏,我想保存用户在搜索栏中所做的更改,并且应该在下次他打开应用程序时显示。我的代码是
@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));
);
【问题讨论】:
【参考方案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);
希望对你有所帮助
【讨论】:
【参考方案2】:在 onPause 中将搜索栏进度保存到共享首选项,并在 onResume 中从共享首选项设置搜索栏进度
【讨论】:
以上是关于Seekbar想要保存进度[重复]的主要内容,如果未能解决你的问题,请参考以下文章
Android SeekBar,动态显示进度且随SeekBar一起移动