Introduction

Slider UI elements enable users to set values by moving a scrubber to a position on a track.

Configuration

Slider UI elements can appear in two different forms:

Continuous The scrubber moves smoothly along the track – any position represents a valid input.
Segmented The scrubber snaps to fixed positions along the track

Also it has the following variations

Point No fill on the track.
Fill Track fills with orange highlight.

Creation

You need to create a new com.att.widgets.lib.control.SliderControl object and add it to your view or layout.

Full layout code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:att="http://schemas.android.com/apk/res/com.att.control"
	android:layout_width="fill_parent" 
	android:layout_height="wrap_content">
	<TextView android:id="@+id/textFieldslider" 
		  android:layout_width="fill_parent" 
		  android:layout_height="wrap_content" 
		  android:text="This is a continuous Slider Control example."  
		  android:textStyle="bold"
		  android:paddingBottom="10dp"/>
 	<com.att.widgets.lib.control.SliderControl
		  android:id="@+id/slider_bar_1"
		  android:layout_width="fill_parent" 
		  android:layout_height="wrap_content" 
		  android:layout_below="@id/textFieldslider"
		  att:max_value="100"
		  att:min_value="0"
		  att:divide_in="4"	
		  att:current_value="5"/>
	<TextView android:id="@+id/slide_bar_1_text" 
		  android:layout_width="fill_parent" 
		  android:layout_height="wrap_content" 
		  android:layout_below="@id/slider_bar_1"
		  android:text="Value: 10"  
		  android:paddingBottom="10dp"/>
	<TextView android:id="@+id/textFieldslider2" 
		  android:layout_width="fill_parent" 
		  android:layout_height="wrap_content" 
		  android:text="This is a segmented Slider Control example."  
		  android:textStyle="bold"
		  android:layout_below="@id/slide_bar_1_text"
		  android:paddingBottom="10dp"/>	  
	<com.att.widgets.lib.control.SliderControl
		  android:id="@+id/slider_bar_2"
		  android:layout_width="fill_parent" 
		  android:layout_height="wrap_content" 
		  android:layout_below="@id/textFieldslider2"
		  att:max_value="100"
		  att:min_value="-100"
		  att:divide_in="4"
		  att:current_value="-50"/>
	<TextView android:id="@+id/slide_bar_2_text" 
		  android:layout_width="fill_parent" 
		  android:layout_height="wrap_content" 
		  android:layout_below="@id/slider_bar_2"
		  android:text="Value: 10"  
		  android:paddingBottom="10dp"/>
	<TextView android:id="@+id/textFieldslider3" 
		  android:layout_width="fill_parent" 
		  android:layout_height="wrap_content" 
		  android:text="This is a disabled Slider Control example."  
		  android:textStyle="bold"
		  android:paddingBottom="10dp"
		  android:layout_below="@id/slide_bar_2_text"/>	 	  
	<com.att.widgets.lib.control.SliderControl
		  android:id="@+id/slider_bar_3"
		  android:layout_width="fill_parent" 
		  android:layout_height="wrap_content" 
		  android:layout_below="@id/textFieldslider3"
		  att:max_value="20"
		  att:min_value="0"
		  att:divide_in="2"
		  att:current_value="5"/>
		  
	<TextView android:id="@+id/slide_bar_3_text" 
		  android:layout_width="fill_parent" 
		  android:layout_height="wrap_content" 
		  android:layout_below="@id/slider_bar_3"
		  android:text="Value: 10"  
		  android:paddingBottom="10dp"/>
	

</RelativeLayout>

Activity

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.att.widgets.lib.control.SliderControl;

public class SliderControlActivity extends Activity implements OnClickListener{

	private SliderControl slider_1, slider_2, slider_3;
	private TextView sliderText_1, sliderText_2, sliderText_3;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        slider_1 = (SliderControl)findViewById(R.id.slider_bar_1);
        slider_2 = (SliderControl)findViewById(R.id.slider_bar_2);
        slider_2.setStep(50.0f);
        slider_3 = (SliderControl)findViewById(R.id.slider_bar_3);
        
        sliderText_1 = (TextView)findViewById(R.id.slide_bar_1_text);
        sliderText_2 = (TextView)findViewById(R.id.slide_bar_2_text);
        sliderText_3 = (TextView)findViewById(R.id.slide_bar_3_text);
        
        slider_2.setProgressFillColor(true);
        slider_3.setEnabled(false);
        
        slider_1.setOnClickListener(this);
        slider_2.setOnClickListener(this);
        slider_3.setOnClickListener(this);
        
    }

	@Override
	public void onClick(View v) {
		if (v == slider_1) {
			sliderText_1.setText("Value: " + slider_1.getCurrent());
		} else if (v == slider_2){
			sliderText_2.setText("Value: " + slider_2.getCurrent());
		} else if (v == slider_3){
			sliderText_3.setText("Value: " + slider_3.getCurrent());
		}
	}
}

Selected Value

This method returns the current selected value

slider.getCurrent()

Continuous and Segmented Configuration

If you use this method to set the step, then the slider will be segmented. Otherwise it will be continuous

        slider.setStep(50.0f);

Fill and Point Configuration

If you set

        slider.setProgressFillColor(true);

the slider control becomes a fill type slider. If this property is not set or if it is set to false, the slider type is 'point'.

Attributes

max_value max limit of Slider Control
min_value min limit of Slider Control
divide_in number of segments divided
current_value current bar value