问题
I have a seekbar in android app to capture the values that ranges from 10-90. What is the java code for capuring the values.
please help Thanks.
回答1:
public class seekbar extends Activity {
private SeekBar seekBar;
private TextView textView;
private int newProgressValue,currentProgress=10;
private SharedPreferences sharedPreferences ;
private String Key_PROGRESS = "key_progress";
private String PREFERENCE_PROGRESS = "preference_progress";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sharedPreferences = getSharedPreferences(PREFERENCE_PROGRESS , Context.MODE_PRIVATE);
currentProgress = sharedPreferences.getInt(Key_PROGRESS, 10);
setContentView(R.layout.main);
textView=(TextView)findViewById(R.id.radious);
seekBar=(SeekBar)findViewById(R.id.seekbar);
seekBar.setMax(90);
seekBar.setProgress(currentProgress);
textView.setText(String.valueOf(currentProgress));
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
newProgressValue = seekBar.getProgress();
currentProgress = newProgressValue ;
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(Key_PROGRESS, newProgressValue);
editor.commit();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
textView.setText(String.valueOf(seekBar.getProgress()));
}
});
} }
回答2:
You can use seekbar.onSeekbarChangeListener
for this.See this link for official java doc..
来源:https://stackoverflow.com/questions/4745639/android-seekbar-widget