How to display some value on seekbar as default?

I have a seekbar for example: from 0 to 10. How can I make if I want to set seekbar to 5 as default position. So in this example seekbar should start from middle.


Use this one


Like "progress", it inherits some of it's attributes from ProgressBar. You find all the attributes at

To get Seekbar at the value of 5

In the xml layout use the max value as 10


In the java for seekbar to get at progress 5

 seekbar = (SeekBar) findViewById(;

thats it :)

I hope this code surely helps you. Try this...

float discrete=0; 
 float start=0; 
 float end=100; 
 float start_pos=0; 
 int start_position=0; 

public void onCreate(Bundle savedInstanceState) { 

    start=-10;      //you need to give starting value of SeekBar 
end=10;         //you need to give end value of SeekBar 
    start_pos=5;    //you need to give starting position value of SeekBar 

    start_position=(int) (((start_pos-start)/(end-start))*100); 
    SeekBar seek=(SeekBar) findViewById(; 
    seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { 

        public void onStopTrackingTouch(SeekBar seekBar) { 
            // TODO Auto-generated method stub 
            Toast.makeText(getBaseContext(), "discrete = "+String.valueOf(discrete), Toast.LENGTH_SHORT).show(); 

        public void onStartTrackingTouch(SeekBar seekBar) { 
            // TODO Auto-generated method stub 


        public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) { 
            // TODO Auto-generated method stub 
            // To convert it as discrete value 
            float temp=progress; 
            float dis=end-start; 


final Timer timer = new Timer();


timer.schedule(new TimerTask() {

    public void run() {
}, 200, 50);

Need Your Help

adapter-Any real example of Adapter Pattern

oop design-patterns adapter software-design

I want to demonstrate use of Adapter Pattern to my team. I've read many books and articles online. Everyone is citing an example which are useful to understand the concept (Shape, Memory Card, Elec...

Java equivalent to #region in C#

java c# eclipse folding

I want to use regions for code folding in Eclipse; how can that be done in Java?