How to call from code onProgressChanged for SeekBar? - android

How to call from code onProgressChanged for SeekBar ? Is there similiar stuff like perform click for button ?

Use this listener on seek bar object
SeekBar seek=new SeekBar(this);
seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// Here call your code when progress will changes
}
});

Related

running a method when a seekbar changes in any way

I need to run a method every time the position of my seekbar is changed.
It does not matter:
how far it has moved
the direction
if its at the end or the start.
just that it has changed
is there a equivalent to onclickListener() for a seekbar.
Use this method provided by SeekBar class:
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//progress changed
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
The seekbar has a setOnSeekBarChangeListener. Check this for more details https://developer.android.com/reference/android/widget/SeekBar.OnSeekBarChangeListener.html
seekBar.setOnSeekBarChangeListener(
new OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar,
int progresValue, boolean fromUser) {
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});

Implementation of seekbar start code function write in stop fuction in media player

i want to convert write onprogress function into stop. means when is release seekbar then volume is up and down.
sB.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i/*progress*/, boolean b) {
aM.setStreamVolume(AudioManager.STREAM_MUSIC,i,0);
// Log.i("Progress","Called"+i);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.i("Start","Called");
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
Log.i("Stop","Called");
}
});
Do like this::
private int volumLevel = 0;
sB.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int i/*progress*/, boolean b) {
if(b){
volumLevel = i;
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.i("Start","Called");
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
aM.setStreamVolume(AudioManager.STREAM_MUSIC,volumnLevel,0);
Log.i("Stop","Called");
}
});
asper our knowledge onStopTrackingTouch event is called after releasing seekbar, so you can update your volume when called.
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
//update your volume using
seekBar.getProgress();
}

Changing textview's value using 2 seekbar

I have 2 seekbars for setting up a timer one for hours and 1 for minutes. I want to show the total duration of the timer by getting the progress of the 2 seekbar and inserting it in 1 textview with a hh:mm format without using any button.
here are my seekbars:
hseek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int shours;
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
shours = progress;
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
hours = shours;
}
});
mseek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int smins;
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
smins = progress;
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
mins = smins;
}
});
You are saving the progress value of both of the seek bars in two variables, set the textview's text in OnStopTrackingTouch in both of the listeners
like this
yourTextview.setText(String.format("%02d:%02d", hours, mins));

How to simultaneously change the value of one seekbar based on other

Have three seekbars on one Activity. All of them have max of 100. I need to sum of all three was 100.
When seek1=50 and seek2=45 then seek3 must be 5.
When I slide seek1 to 55 seek3 must have 0. etc.
How can I code this?
Sorry, here is my code:
//01
final SeekBar seekBar01 = (SeekBar)findViewById(R.id.seek01);
final TextView seekBar01Value = (TextView)findViewById(R.id.txt01val);
seekBar01.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
seekBar01Value.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
//02
SeekBar seekBar02 = (SeekBar)findViewById(R.id.seek02);
final TextView seekBar02Value = (TextView)findViewById(R.id.txt02val);
seekBar02.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
seekBar02Value.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
//03
SeekBar seekBar03 = (SeekBar)findViewById(R.id.seek03);
final TextView seekBar03Value = (TextView)findViewById(R.id.txt03val);
seekBar03.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
seekBar03Value.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
I can show values on respective TextViews, but don't get how to change another seebar progress from other seekbar onProgressChanged.
Set OnSeekBarChangeListener to your seekbars. When one changes, set the values to the others with setProgress
Trouble was because of late declarations of SeekBar's.
If gather all SeekBar seekBarXX = (SeekBar)findViewById(R.id.seekXX); sooner than Change listeners all works as expected.
Sorry for stupidity.
Here is code:
final SeekBar seekBar01 = (SeekBar)findViewById(R.id.seek01);
final SeekBar seekBar02 = (SeekBar)findViewById(R.id.seek02);
final SeekBar seekBar03 = (SeekBar)findViewById(R.id.seek03);
seekBar01.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
seekBar02.setProgress(100-seekBar01.getProgress());
}
...
});

Multiple vertical seekbar

I want to implement 3 vertical SeekBar in a page so that it looks like a bar chart. When user drags any one of the SeekBar the value corresponding to the y axis should be retrieved for that. Other SeekBar should remain in their original state.
Our idea is to implement interactive bar chart with dragging feature. Since that is not possible in open library, we decided to use seek bar instead by increasing the width.
Any sample app with this will be helpful.
public class multiverticleseek extends Activity {
/** Called when the activity is first created. */
TextView textView3,textView2,textView1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.multiseek);
textView1 = (TextView)findViewById(R.id.textView1);
textView2 = (TextView)findViewById(R.id.textView2);
textView3 = (TextView)findViewById(R.id.textView3);
bar1=(VerticalSeekBar)findViewById(R.id.seekBar1);
bar2=(VerticalSeekBar)findViewById(R.id.seekBar2);
bar3=(VerticalSeekBar)findViewById(R.id.seekBar3);
bar1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
textView1.setText(Integer.toString(progress)+"%");
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
bar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
textView2.setText(Integer.toString(progress)+"%");
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
bar3.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
textView3.setText(Integer.toString(progress)+"%");
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}

Categories

Resources