opened
farzadkamali20
username_0
hi friend,
in TableViewListener we access to cellview and can access to CellViewHolder.

Cell cell = (Cell) mTableView.getAdapter().getCellItem(column,row);
        if (cellView instanceof CheckBoxCellViewHolder ) {
            if (((CheckBoxCellViewHolder) cellView).checkBox.isChecked()) {
                ((CheckBoxCellViewHolder) cellView).checkBox.setChecked(false);
                cell.setbData(false);
            } else {
                ((CheckBoxCellViewHolder) cellView).checkBox.setChecked(true);
                cell.setbData(true);
            }
        }

but i want access to CheckBoxViewHolder and set checkbox to true or false in activity(no in TableViewListener ).

i use this code :  
 for (int i = 0; i < tableView.getChildCount(); i++) {
**tableView.getCellLayoutManager().getCellViewHolder(3, i)).checkBox.setChecked(false);**
}

but not worked properly when scroll table and error : 

 'android.widget.CheckBox com.example.farzad.charge.tableview.CheckBoxCellViewHolder.checkBox' on a null object reference
how to access cellViewHolder
issue
created
evrencoskun
username_1
You shouldn't change the checkbox state like the way you do. You should just change the model value and update the item like 

For example;
let's say your cell item has an instance like `mChecked`;

```java
class Cell{
...
public int mChecked;
...
}
```

when it's binding, it'll show the model data like you do.


```java
CheckBoxViewHolder {
..
public void setCell(Cell cell){
     boolean checked = cell.getData() == 1;
    mCheckBox.setState(checked);
}
..
}
```

So, how can you change any checkbox state? 

you just need to update the model of the cell item using 
`changeCellItem(int columnPosition, int rowPosition, YourCellModel cellModel)` function of the TableViewAdapter

```java
int row = 4;
int column = 2;
// get Cell item 
Cell cellModel = tableViewAdapter.getCellItem(column , row );
// Update the state o the checkbox
cellModel .mChecked = 1;
// Notify the TableView for changing process.
tableViewAdapter.changeCellItem(column , row , cellModel); 
```
comment
closed
farzadkamali20
username_0
issue