0

我正在使用搜索栏,我想保存用户在搜索栏中所做的更改,并且应该在下次他打开应用程序时显示。我的代码是

@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)); 

            } 
        }); 
    } 
}
4

2 回答 2

1

检查这篇文章- 并尝试了解如何优先保存数据。然后在你的活动中

@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);
}

希望它的帮助

于 2013-04-09T12:44:49.897 回答
0

在 onPause 中将搜索栏进度保存到共享首选项,并在 onResume 中从共享首选项设置搜索栏进度

于 2013-04-09T12:34:44.090 回答