Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- static class Timer {
- static boolean active = true;
- static int level = 100;
- static int start = 3650;
- static int stop = 7200;
- }
- static class Pump{
- static boolean active = true;
- static int start = 3600;
- static int working = 3000;
- }
- static class CO2{
- static boolean active = true;
- static Timer[] timerCO2 = new Timer[4];
- }
- static class Channel{
- static boolean active = true;
- static int startDay = 3600;
- static int stopDay = 82800;
- static Timer[] timer = new Timer[4];
- }
- Channel[] channel = new Channel[9];
- public int chNum;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final Switch switchCh = (Switch) findViewById(R.id.switchCh);
- final ArrayAdapter<String> adapterCh = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ch);
- adapterCh.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- Spinner spinnerCh = (Spinner) findViewById(R.id.spinnerCh);
- spinnerCh.setAdapter(adapterCh);
- spinnerCh.setSelection(0);
- spinnerCh.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView<?> parent, View view,
- int position, long id) {
- chNum = position;
- switchCh.setChecked(channel[chNum].active);
- System.out.println ("spinnerCh " + chNum + " " + channel[chNum].active);
- }
- @Override
- public void onNothingSelected(AdapterView<?> arg0) {
- }
- });
- switchCh.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- channel[chNum].active = isChecked;
- System.out.println ("switchCh " + chNum + " " + channel[chNum].active);
- }
- });
- }
- }
- switchCh.setOnCheckedChangeListener (null);
- switchCh.setChecked (..);
- switchCh.setOnCheckedChangeListener ( листенер сохраненый в переменную в OnCreate);
Add Comment
Please, Sign In to add comment