android seekbar widget

馋奶兔 提交于 2020-01-03 05:27:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!