Reputation: 2741
The maximum value of SeekBar
is 100 then How to set a Seekbar
values default as 50 (starting at 50%). The seek bar will be start at 50.
I got a sample code but it will start at 0 to 100. Please answer me if you have any idea... Thank you.
public class MainActivity extends Activity implements OnSeekBarChangeListener{
private SeekBar bar; // declare seekbar object variable
// declare text label objects
private TextView textProgress,textAction;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// load the layout
setContentView(R.layout.activity_main);
bar = (SeekBar)findViewById(R.id.seekBar1); // make seekbar object
bar.setOnSeekBarChangeListener(this); // set seekbar listener.
// since we are using this class as the listener the class is "this"
// make text label for progress value
textProgress = (TextView)findViewById(R.id.textViewProgress);
// make text label for action
textAction = (TextView)findViewById(R.id.textViewAction);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
// change progress text label with current seekbar value
textProgress.setText("The value is: "+progress);
// change action text label to changing
textAction.setText("changing");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
textAction.setText("starting to track touch");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
seekBar.setSecondaryProgress(seekBar.getProgress());
textAction.setText("ended tracking touch");
}
}
Upvotes: 0
Views: 29424
Reputation: 576
Set the MaxValue once before you set the progress value . In that way the system knows what proportion of the seekbar has to be colored.
Upvotes: 0
Reputation: 9103
in XML :
android:progress="50" // or any other value
in Java :
mSeekbar.setProgress(50); // or any other value
and if you don't know what's the Max Value and just want to make it 50%:
mSeekbar.setProgress(mSeekbar.getMax()/2);
Upvotes: 22
Reputation: 4117
See this and here is how you can do
seekBar.setMax(0);
seekBar.setMax(100);
seekBar.setProgress(50);
in xml you can do like this android:progress="50"
Upvotes: 2