+ Reply to Thread
Results 1 to 2 of 2

Thread: Discrete seekbar in Android app?

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    8

    Discrete seekbar in Android app?

    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.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    14
    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.
    Code:
     <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>

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts