dimanche 23 août 2015

Android multiple checkboxes

Basically I got 5 rows of 5 checkboxes, this is just one row. As you can notice it's messy and having 5 of these is even worse.

I just started learning android so I'm not yet familiar with the options I got, but normally I think I'd either put all the boxes in an array and iterate through it, or make a JPanel for one row and add the panel 5 times.

What's the best way to do this and why?

     /**
     * Row 1 checkboxes
     */
    CheckBox row1box1 = (CheckBox) findViewById(R.id.row1checkBox1);
    CheckBox row1box2 = (CheckBox) findViewById(R.id.row1checkBox2);
    CheckBox row1box3 = (CheckBox) findViewById(R.id.row1checkBox3);
    CheckBox row1box4 = (CheckBox) findViewById(R.id.row1checkBox4);
    CheckBox row1box5 = (CheckBox) findViewById(R.id.row1checkBox5);
    row1box1.setOnClickListener(new StartListener(row1box1, chronometer, ringtone));
    row1box2.setOnClickListener(new StartListener(row1box2, chronometer, ringtone));
    row1box3.setOnClickListener(new StartListener(row1box3, chronometer, ringtone));
    row1box4.setOnClickListener(new StartListener(row1box4, chronometer, ringtone));
    row1box5.setOnClickListener(new StartListener(row1box5, chronometer, ringtone));

Aucun commentaire:

Enregistrer un commentaire