-2

enter image description here

**There is a switch button , seek bar and text view in the above image
so when this activity starts . i want seek bar and the text view invisible by default and when i switch on the switch button , both seek bar and text view should be visible please provide a simple code for this operation .

i have tried using all gone ,visible and invisible stuffs . but it is not showing any effect.

**

Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177
Akash B
  • 31
  • 1
  • 1
  • 6

1 Answers1

0

have you tried like below?

@Override
    protected void onCreate(Bundle savedInstanceState){
    setContentView(R.layout.activity_main);

    // find all view id here

    textview.setVisiblity(View.GONE);
    seekBar.setVisiblity(View.GONE);

    mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // do something, the isChecked will be
            // true if the switch is in the On position
            if(isChecked){
              textview.setVisiblity(View.VISIBLE);
              seekBar.setVisiblity(View.VISIBLE);
            }else{
              textview.setVisiblity(View.GONE);
              seekBar.setVisiblity(View.GONE);
            }
        }
    });
    }
Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177