0

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.

4

2 回答 2

3

公共类搜索栏扩展活动{

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

        }
    });


} }
于 2011-01-20T13:38:47.427 回答
1

你可以使用seekbar.onSeekbarChangeListener这个。请参阅此链接以获取官方 java 文档 ..

于 2011-01-20T11:38:44.170 回答