evrencoskun / TableView

TableView is a powerful Android library for displaying complex data structures and rendering tabular data composed of rows, columns and cells.
MIT License
3.14k stars 454 forks source link

hideColumn not work when hide 2 or more columns #322

Open afh905 opened 4 years ago

afh905 commented 4 years ago

Hi

First of all, Thank you for this amazing library!

I have a problem with the hideColumn method in Tableview. When I remove my first column, all work fine but, in the second hide, if the column to hide is previous the column than i removed before, the hidden column is not correct. I think the problem are with the method getSmallerHiddenCount in VisibilityHandler. This method increment count ever I previously hide a column and it is added to mHideColumnList

   private <T> int getSmallerHiddenCount(int index, SparseArray<T> list) {
        int count = 0;
        for (int i = 0; i < index && i < list.size(); i++) {
            if (list.valueAt(i) != null) {
                count++; // This line is called independent the hidden column is 0 or 4
            }
        }
        return count;
    }

The steps to reproduce this error are:

  1. I hide column at position 4. getSmallerHiddenCount return 0 and convertIndexToViewIndex return 4. This is correct. The column 4 now is hidden and its is added in mHideColumnList with position 0.
  2. I want to hide now the column 3. when getSmallerHiddenCount run it checks that "if (list.valueAt(0) != null)" is true but i didn't hide column in position 0, I hid column in position 4 but it is saved in position 0 of the list. I think this is the error. this method return 1 and convertIndexToViewIndex return 2 (3-1) and hide column in position 2 that is not correct column.

I think that getSmallerHiddenCount should check that the elements in mHideColumnList has a key < to the desire position to hide and not position in the list.

Thanks!!

afh905 commented 4 years ago

I see that this error appears in this version 0.8.9.2 with changes in #301. In the version 0.8.9 the code for getSmallerHiddenCount is correct:

   private  int getSmallerHiddenCount(int index, SparseArray list) {
        int count = 0;
        for (int i = 0; i < index; i++) {
            int key = list.keyAt(i);
            // get the object by the key.
            if (list.get(key) != null) {
                count++;
            }
         }