jeudi 3 mai 2018

Get generated checkbox Checked State

I generate checkboxes with the following code:

public void drawCAnswers(int pst){
    rcflag = 1;
    int drawables = qmclist.get(pst).getAnswers().size();
    LinearLayout ll = new LinearLayout(this);
    CheckBox[] cbs = new CheckBox[drawables];
    ll.setOrientation(LinearLayout.VERTICAL);
    for (int i=0; i<drawables;i++){
        cbs[i] = new CheckBox(this);
        cbs[i].setId(i);
        cbs[i].setText(current.getAnswers().get(i).getAns());
        ll.addView(cbs[i]);
    }
    parentLinearLayout.addView(ll, parentLinearLayout.getChildCount());
}

I would like to be able, upon clicking a button, to check which of the checkboxes are selected, and get their text. How exactly could I accomplish this with my code?

Setting an onClick Listener doesn't seem right, because it's only when I click the "Next" button that I should see which ones are checked, it doesn't matter if before clicking someones (de)selects a checkbox.

Thanks a lot.




Aucun commentaire:

Enregistrer un commentaire