samedi 25 novembre 2017

How to check if checkbox is checked in a specific row?

I generated a table which has checkboxes at the end of every row. I want to sum all of values in the specific row if the checkbox is selected in that row. Therefore I need to check if the checkbox is checked in that specific row. So far I have this:

btnCalculate.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        try {
            int sum = 0;
            for(int i=0; i<rowNumber; i++) {
                if(cb.isChecked()) {
                    sum = sum + rowSums[i];
                }
            }
            txtResult.setText(String.valueOf(sum));
        } catch (Exception e) { }
    }
});

Normally, I can access the values of all cells withing a row and I am able to sum all of those values inside the row. However, when I add if statement inside the sum, I always get 0. I know what is the problem. I know I have to check if the checkbox is checked in that specific row. But I don't know how to do that. By the way I also set IDs for every checkboxes inside the row. For example, ID of the first row's checkbox is 0 and the second row's is 1 and so on. So I just have to access that specific checkbox and check if it is checked.




Aucun commentaire:

Enregistrer un commentaire