views:

628

answers:

4

i would like to create a seekbar for an Android app that allows the user to select a value between -5 and 5 (which maps to "strongly disagree" and "strongly agree"). how do i make a seekbar with discrete values? or is there a better UI widget i could use for this?

thanks.

+1  A: 

I don't know what is the issue here, you add a seekbar having a range of 0-10. Then you can map these values to -5 if you substract -5 from the selected value.

EDIT

add android:max="10" to the xml definiton and you get a fixed size seekbar.

You maybe should consider to add a textview to denote the current selected value's textual representation such as: Strongly Disagree. To update this view, subscribe to onProgressChanged event and progress parameter will give you the chosen number.

SeekBar s = (SeekBar) findViewById(R.id.SeekBar);
s.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                    @Override
                    public void onProgressChanged(SeekBar seekBar,
                            int progress, boolean fromUser) {
                                    }
}
Pentium10
i thought seekbars always look and act continuous? i was hoping for a way to show tick marks for the values, and for interaction with the bar to feel discrete.
vee
`SeekBar` returns an integer value, so it will be discrete numerically, at least.
CommonsWare
+1  A: 

The Seekbar works great for discrete values. We use a Seekbar for discrete data as shown below. To show which item is selected, we just change the font of the selected text view so it is bigger. You could also highlight by changing the background color or something. It works pretty well. You will want to call setMax(11) on the seek bar, and then in your code you need to translate between the range (0 through 11) and (-5 through 5) appropriately.

 <LinearLayout 
           android:orientation="vertical"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:gravity="center_horizontal">
     <LinearLayout 
           android:orientation="horizontal"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:gravity="center_horizontal">
    <TextView android:text="-5"
            android:id="@+id/answerNegative5"
            android:textSize="25sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    <TextView android:text="-4"
            android:id="@+id/answerNegative4"
            android:textSize="25sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    <TextView android:text="-3"
            android:id="@+id/answerNegative3"
            android:textSize="25sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    .....
  </LinearLayout>

  <SeekBar android:id="@+id/intensitySlider"
                    android:layout_weight="0"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />
</LinearLayout>
Jay Askren
A: 

Check this thread.

I am using it in my app.

Macarse
A: 

Hi, How can I use seek bar for the time control of streaming video?

Asma-ull-Hosna
This isn't an answer. Please post your own question or add a comment to the above question.
colithium