Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple SeekBars listener

I have multiple seekbar on the same view :

barheures = (SeekBar)findViewById(R.id.barheures); // make seekbar object
        barheures.setOnSeekBarChangeListener(this); // set seekbar listener.
        // since we are using this class as the listener the class is "this"
        barminutes = (SeekBar)findViewById(R.id.barminutes);
        barminutes.setOnSeekBarChangeListener(this); 

And here is the listener:

@Override
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) {
    // TODO Auto-generated method stub
    Log.v("", "" + bar);
    textMinutes.setText("" + progress + "Minute(s)" );
    textHours.setText("" + progress + "Heure(s)" );
}

I wanna make something different if the first OR the second bar have moved into the same listener (is it the good practice?), but how to?? Here I have the app that don't do what I want

like image 258
clement Avatar asked Jan 03 '12 22:01

clement


1 Answers

Now then you have 2 seekbars with the following ids:

  1. barheures - its id: R.id.barheures
  2. barminutes - its id: R.id.barminutes

Now in the onProgressChanged(SeekBar bar, int progress, boolean fromUser) method, Do the following:

@Override
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) {
    // TODO Auto-generated method stub
    Log.v("", "" + bar);

    switch (bar.getId()) {

    case R.id.barheures:
        textHours.setText("" + progress + "Heure(s)");
        break;

    case R.id.barminutes:
        textMinutes.setText("" + progress + "Minute(s)");
        break;
    }
}


    
like image 179
King RV Avatar answered Sep 28 '22 10:09

King RV