问题描述:

Im trying to make a meter/bar that the user can use in order to choose a specific value (for example; when the user wants to rate something between 1-10 etc). By sliding the bar left the value gets smaller and vice versa. Any ideas/hints to implement something like this would be much appreciated!

网友答案:

You can use a SeekBar.

http://developer.android.com/reference/android/widget/SeekBar.html

Drop a SeekBar in your layout and get a handle on it in your code. You can react to changes in the SeekBar by implementing a OnSeekBarChangeListener.

Here's a snippet to get you going:

seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
          int progress = 0;

          @Override
          public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
              progress = progresValue;
              Toast.makeText(getApplicationContext(), "Changing seekbar's progress", Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {
              Toast.makeText(getApplicationContext(), "Started tracking seekbar", Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
              textView.setText("Covered: " + progress + "/" + seekBar.getMax());
              Toast.makeText(getApplicationContext(), "Stopped tracking seekbar", Toast.LENGTH_SHORT).show();
          }
       });
相关阅读:
Top