Skip to content

1.5. Setting the Adapter

Evren Coskun edited this page Apr 4, 2020 · 2 revisions

To be able to set your Adapter to your TableView, you need to organize your data as TableView wants.

AbstractTableAdapter class requires 3 different lists which represent respectively; ColumnHeader, RowHeader and Cell ViewModels.

Create 3 item lists using the Data Models.
The List<List<Cell>> mCellList inner List is for the items of the Columns and the outer List are for the Rows.

For the example adapter these Lists should be populated with String Objects.

   private List<RowHeader> mRowHeaderList;
   private List<ColumnHeader> mColumnHeaderList;
   private List<List<Cell>> mCellList;

Setting data using our TableView adapter like this:

   TableView tableView = new TableView(getContext());
   
   // Create our custom TableView Adapter
   MyTableViewAdapter adapter = new MyTableViewAdapter(getContext());
   
   // Set this adapter to the our TableView
   tableView.setAdapter(adapter);
   
   // Let's set datas of the TableView on the Adapter
   adapter.setAllItems(mColumnHeaderList, mRowHeaderList, mCellList);