1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| package mormic.mux;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Switch;
import android.widget.TextView;
import java.util.ArrayList;
public class Programme extends ActionBarActivity {
private ArrayList<Switch> listeSwitch = new ArrayList<>();
TextView Affiche, Tag;
Button bouton;
Switch sw0,sw1,sw2,sw3,sw4,sw5,sw6,sw7,sw8,sw9,sw10,sw11,sw12,sw13,sw14;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_programme);
Affiche = (TextView) findViewById(R.id.txtMsg);
Tag = (TextView) findViewById(R.id.tagMsg);
sw0 = (Switch) findViewById(R.id.switch0);
listeSwitch.add(sw0);
sw1 = (Switch) findViewById(R.id.switch1);
listeSwitch.add(sw1);
sw2 = (Switch) findViewById(R.id.switch2);
listeSwitch.add(sw2);
sw3 = (Switch) findViewById(R.id.switch3);
listeSwitch.add(sw3);
sw4 = (Switch) findViewById(R.id.switch4);
listeSwitch.add(sw4);
sw5 = (Switch) findViewById(R.id.switch5);
listeSwitch.add(sw5);
sw6 = (Switch) findViewById(R.id.switch6);
listeSwitch.add(sw6);
sw7 = (Switch) findViewById(R.id.switch7);
listeSwitch.add(sw7);
sw8 = (Switch) findViewById(R.id.switch8);
listeSwitch.add(sw8);
sw9 = (Switch) findViewById(R.id.switch9);
listeSwitch.add(sw9);
sw10 = (Switch) findViewById(R.id.switch10);
listeSwitch.add(sw10);
sw11 = (Switch) findViewById(R.id.switch11);
listeSwitch.add(sw11);
sw12= (Switch) findViewById(R.id.switch12);
listeSwitch.add(sw12);
sw13= (Switch) findViewById(R.id.switch13);
listeSwitch.add(sw13);
sw14= (Switch) findViewById(R.id.switch14);
listeSwitch.add(sw14);
}
public void Action(View v) {
int idBtn = v.getId();
int noBtn;
Switch leSwitch;
String txtBtn;
bouton = (Button) findViewById(idBtn);
txtBtn = (String) bouton.getText();
noBtn = Integer.parseInt(txtBtn);
Affiche.setText("Commande N° " + txtBtn + " actionnée");
leSwitch= listeSwitch.get(noBtn);
if (leSwitch.isChecked())
Tag.setText("le switch est le ON");
else
Tag.setText("Le switch est OFF");
}
} |
Partager