Java Android Studio - SortableTableView doesn't work with fragment

Viewed 299

I'm using this library in a couple of apps. In the first app with activities it works perfectly, in the second one with fragments not.

Here the error:

android.view.InflateException: Binary XML file line #9 in com.example.testss:layout/fragment_chiusure: Binary XML file line #9 in com.example.testss:layout/fragment_chiusure: Error inflating class de.codecrafters.tableview.TableView Caused by: android.view.InflateException: Binary XML file line #9 in com.example.testss:layout/fragment_chiusure: Error inflating class de.codecrafters.tableview.TableView

XML:

 <?xml version="1.0" encoding="utf-8"?>
 <androidx.constraintlayout.widget.ConstraintLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".ui.chiusure.tabellachiusureFragment">

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

</androidx.constraintlayout.widget.ConstraintLayout>

Fragment:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_chiusure, container, false);

[...]

TableView<String[]> tableView = (TableView<String[]>) rootView.findViewById(R.id.tabellachiusure);
    tableView.setDataAdapter(new SimpleTableDataAdapter(getContext(),
            result));
    String[] TABLE_HEADERS = { "Tipo", "Data", "Orario", "Stato" };
    tableView.setHeaderAdapter(new SimpleTableHeaderAdapter(getContext(), TABLE_HEADERS));
    TableColumnWeightModel columnModel = new TableColumnWeightModel(4);
    columnModel.setColumnWeight(1, 1);
    columnModel.setColumnWeight(2, 2);
    columnModel.setColumnWeight(3, 1);
    columnModel.setColumnWeight(4, 2);
    tableView.setColumnModel(columnModel);

        return rootView ;
}

The working version with activities is exactly the same except for:

setContentView(R.layout.activity_test_tabella);
    TableView<String[]> tableView = (TableView<String[]>) findViewById(R.id.tabellachiusure);
    tableView.setDataAdapter(new SimpleTableDataAdapter(this,
            result));

Suggestions?

1 Answers

Solved by myself adding this line to my gradle:

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
Related