Cleveroad / AdaptiveTableLayout

Library that makes it possible to read, edit and write CSV files
MIT License
1.9k stars 234 forks source link

Crash while switching rows using the adapter which subcalsses BaseDataAdaptiveTableLayoutAdapter #20

Closed hao33782 closed 5 years ago

hao33782 commented 6 years ago

My code is as follows.

static class MyAdapter extends
        BaseDataAdaptiveTableLayoutAdapter<MyAdapter.ViewHolder> {
    @Override
    protected Object[][] getItems() {
        return cells;
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int row, int column) {
        viewHolder.text.setText(cells[row][column]);
    }

    // other codes...
}

It works well when dragging is not involved. When switching columns, the app doesn't crash. But if rows are switched, it crashes!

I found the following code in the library:

void switchTwoRows(int rowIndex, int rowToIndex) {
    for (int i = 0; i < getItems().length; i++) {
        Object cellData = getItems()[rowToIndex][i];
        getItems()[rowToIndex][i] = getItems()[rowIndex][i];
        getItems()[rowIndex][i] = cellData;
    }
}

I think getItems().length should not be used here. It just gives number of rows of my data... It should be something like getColumnCount() - 1. Is it my misunderstanding? Any comment is appreciate.

VadimHalimendikCr commented 5 years ago

HI, we cannot reproduce this bug. You can give us more information?