How to dynamically move seekbar from another seekbar in android? - android

I need to dynamically move 2 seekbars. While the user moves one, the other will have to move also accordingly to the values of the first.
I've created 2 seekbars but they move independent from each other, how can i "link" them so, for ex. the second seekbar moves 1/10th of the first?
Thanks
seekBarSM.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
#Override
public void onProgressChanged(SeekBar seekBarSM, int progress,
boolean fromUser) {
seekBarSMValue.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBarSM) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBarSM) {
}
});
seekBarSF.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
#Override
public void onProgressChanged(SeekBar seekBarSF, int progress,
boolean fromUser) {
seekBarSFValue.setText(String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBarSF) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBarSF) {
}
});

In the onProgressChanged() of one, just call setProgres() on the other with the value it should change to.

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) {
}
});

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) {
}
});
}

Sliding 1 seekbar is causing Both Seekbars to change thumbs

This is a strange one. I have 2 seek bars and I have established a listener for both. However when I slide the thumbbar for one seekbar - it updates that seekbar AND it also moves the thumb of the second seekbar.
If I move the thumb on the second seekbar - it only changes the second sekbar NOT the first.
If I remove the listener for the first seekbar - I get the same problem.
I have attached code pertiaing to the seekbar listeners. mSeekBarA is the first one. mSeekBarB is the second.
mSeekBarA.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
#Override
public void onStopTrackingTouch(SeekBar seekBar)
{
}
#Override
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
On_SFX_Volume_Change(progress);
}
});
mSeekBarB.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
#Override
public void onStopTrackingTouch(SeekBar seekBar)
{
}
#Override
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
On_MUS_Volume_Change(progress);
}
});
Thank you !
How did you instantiate these sliders? I bet that they are actually referring to the same instance. Possibly you added the same slider to the layout instead of adding the each one individually.

Categories

Resources