package com.example.ghomi.chapter3_3;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ToggleButton;
import android.widget.TextView;
import android.widget.Switch;

public class MainActivity extends AppCompatActivity {
    private ToggleButton toggleButton1, toggleButton2;
    private Button btnDisplay;
    TextView tv;
    Switch sh;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addListenerOnButton();
    }
    public void addListenerOnButton() {
        toggleButton1 = (ToggleButton) findViewById(R.id.toggleButton1);
        toggleButton2 = (ToggleButton) findViewById(R.id.toggleButton2);
        btnDisplay = (Button) findViewById(R.id.btnDisplay);
        tv = (TextView)findViewById(R.id.textView);
        sh = (Switch) findViewById(R.id.switch1);
        btnDisplay.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
              String s = "";
              s = toggleButton1.getText().toString();
              s += "\r\n";
              s = s + toggleButton2.getText();
              s += "\r\n";
              if (sh.isChecked())
                    s = s + sh.getTextOn();
                    else
                       s = s + sh.getTextOff();
                    tv.setText(s);
              }
      });
    }

}
