Guest User

Untitled

a guest
May 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2. static class Timer {
  3. static boolean active = true;
  4. static int level = 100;
  5. static int start = 3650;
  6. static int stop = 7200;
  7. }
  8.  
  9. static class Pump{
  10. static boolean active = true;
  11. static int start = 3600;
  12. static int working = 3000;
  13. }
  14.  
  15. static class CO2{
  16. static boolean active = true;
  17. static Timer[] timerCO2 = new Timer[4];
  18. }
  19. static class Channel{
  20. static boolean active = true;
  21. static int startDay = 3600;
  22. static int stopDay = 82800;
  23. static Timer[] timer = new Timer[4];
  24. }
  25. Channel[] channel = new Channel[9];
  26.  
  27. public int chNum;
  28.  
  29. @Override
  30. protected void onCreate(Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. setContentView(R.layout.activity_main);
  33.  
  34. final Switch switchCh = (Switch) findViewById(R.id.switchCh);
  35. final ArrayAdapter<String> adapterCh = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ch);
  36. adapterCh.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  37. Spinner spinnerCh = (Spinner) findViewById(R.id.spinnerCh);
  38. spinnerCh.setAdapter(adapterCh);
  39. spinnerCh.setSelection(0);
  40. spinnerCh.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  41. @Override
  42. public void onItemSelected(AdapterView<?> parent, View view,
  43. int position, long id) {
  44. chNum = position;
  45. switchCh.setChecked(channel[chNum].active);
  46. System.out.println ("spinnerCh " + chNum + " " + channel[chNum].active);
  47.  
  48. }
  49. @Override
  50. public void onNothingSelected(AdapterView<?> arg0) {
  51. }
  52. });
  53.  
  54. switchCh.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  55. @Override
  56. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  57. channel[chNum].active = isChecked;
  58. System.out.println ("switchCh " + chNum + " " + channel[chNum].active);
  59. }
  60. });
  61.  
  62. }
  63. }
  64.  
  65. switchCh.setOnCheckedChangeListener (null);
  66. switchCh.setChecked (..);
  67. switchCh.setOnCheckedChangeListener ( листенер сохраненый в переменную в OnCreate);
Add Comment
Please, Sign In to add comment