2013-04-09 91 views
0

我正在使用搜索欄我想保存用戶在seekbar &中所做的更改,每當他打開應用程序時應該顯示下一次。我的代碼是Seekbar想要保存進度

@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

保存搜索條進度,在共享的onPause偏好和從共享偏好設置搜索條進步的onResume

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

希望它的幫助