Skip to content

I/de.codecrafters.tableview.SortableTableView: Unable to sort column with index -1. Reason: no comparator set for this column. #49

@boogerlad

Description

@boogerlad

The example application from the google play store does not exhibit this issue. However, following the instructions from the readme.md file, any time the orientation of the screen changes, the warning (from the title) appears in the debug log. I'm using 2.2.1 on android 6.0

This is the view

<de.codecrafters.tableview.SortableTableView
        xmlns:table="http://schemas.android.com/apk/res-auto"
        android:id="@+id/tableView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

This is the code in a fragment

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_history, container, false);
        SortableTableView<String[]> tableView = (SortableTableView<String[]>) v.findViewById(R.id.tableView);

        String[] header = {"Scan", "Hardware ID", "Timestamp", "blood"};
        tableView.setHeaderAdapter(new SimpleTableHeaderAdapter(getActivity(), header));


        tableView.setColumnCount(4);

        String[][] data = {{"no", "data", "yet", ":("}};
        tableView.setDataAdapter(new SimpleTableDataAdapter(getActivity(), data));
        tableView.setColumnComparator(0, (String[] lhs, String[] rhs)->Integer.parseInt(lhs[0]) - Integer.parseInt(rhs[0]));
        tableView.setColumnComparator(1, (String[] lhs, String[] rhs)->lhs[1].compareTo(rhs[1]));
        tableView.setColumnComparator(2, (String[] lhs, String[] rhs)->lhs[2].compareTo(rhs[2]));
        tableView.setColumnComparator(3, (String[] lhs, String[] rhs)->Integer.parseInt(lhs[3]) - Integer.parseInt(rhs[3]));
        return v;
    }

Interestingly enough, the first instance of this fragment getting created won't display that error/warning onto the log.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions