android seekbar小部件

时间:2011-01-20 09:54:16

标签: android seekbar

我在android应用程序中有一个搜索栏来捕获范围从10到90的值。 capuring the values的java代码是什么。

请帮忙 感谢。

2 个答案:

答案 0 :(得分: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()));

        }
    });


} }

答案 1 :(得分:1)

您可以使用seekbar.onSeekbarChangeListener进行此操作。请参阅此link以获取官方java文档..