Skip to content

1.1. Creating a TableView

Evren Coşkun edited this page Jan 15, 2020 · 1 revision

To display your data on TableView, first of all, you need to create a TableView object.

  1. Programmatically
TableView tableView = new TableView(getContext());
  1. XML
<com.evrencoskun.tableview.TableView
    android:id="@+id/content_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

As default constants can be set programmatically, it can be set by also using xml attributes of TableView like this:

<com.evrencoskun.tableview.TableView
    android:id="@+id/content_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    
    app:column_header_height="@dimen/column_header_height"
    app:row_header_width="@dimen/row_header_width"
    app:selected_color="@color/selected_background_color"
    app:shadow_color="@color/shadow_background_color"
    app:unselected_color="@color/unselected_background_color"
/>

Note: To be able use these attributes on xml side, the xmlns: namespace below line should be added on layout root view. Otherwise, Android Studio gives you compile error.

xmlns:app="http://schemas.android.com/apk/res-auto"
List of defined attributes
  • row_header_width format="dimension"
  • column_header_height format="dimension"
  • selected_color format="color"
  • unselected_color format="color"
  • shadow_color format="color"
  • separator_color format="color"
  • show_vertical_separator format="boolean"
  • show_horizontal_separator format="boolean"
  • allow_click_inside_cell format="boolean"
  • allow_click_inside_row_header format="boolean"
  • allow_click_inside_column_header format="boolean"