How to enable and disable a seekbar when clicked?

4.1k Views Asked by At

Hi guys I have two seekbars A and B and they edit 2 textviews 1 and 2. A edits 1 and B edits 2. I want it to work so that when the user touches seekbar A then seekbar B becomes disabled and likewise when seekbar B is touched by the user seekbar A becomes disabled. However when the app launches seekbar B is automatically disabled. Which i did by setting seekbar b enabled to false. All goo so far as seekbar A allows me to edit textview 1 however my method for enabling seekbar B and disabling seekbar A at the same time did not work. I set both seekbars to have an onclick listener. Then in the click method i have used a switch case statement to say that which ever seekbar is click the other seekbar is set to enabled false.

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

    switch(v.getId()){

        case R.id.seekbar_A:
            seekbarA.setEnabled(true);
            seekbarB.setEnabled(false);
            break;
        case R.id.seekbarB:
            seekbarA.setEnabled(false);
            seekbarB.setEnabled(true);
            break;
    }
}

This all seems good in theory but when I run the app seekbar B is disabled and seekbar A works fine. But then when I touch seekbar B it does not become enabled and neither does seekbar A become disabled. So how do I make this work?

1

There are 1 best solutions below

1
On

You probably want to be setting each seekbar's onSeekBarChange listener. It looks a little something like this:

        SeekBar sb;
        sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });