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.15k stars 457 forks source link

TableView created programmatically not clickable #388

Open davidwong opened 3 years ago

davidwong commented 3 years ago

When a TableView is created with new TableView(context), i.e. not using XML, then it is not clickable.

Looking at the source for TableView (version 0.8.9.4) it seems like the flags to allow clicking are set to false by default: private boolean mAllowClickInsideCell = false; private boolean mAllowClickInsideRowHeader = false; private boolean mAllowClickInsideColumnHeader = false;

When the TableView is inflated from XML these can be set

app:allow_click_inside_cell="true" app:allow_click_inside_row_header="true" app:allow_click_inside_column_header="true"

However they cannot be set programmatically, i.e. there are no setters for these fields. This is kinda understandable since they are used during initialization for the TableView, so really need another constructor to set them I guess.

FYI, I'm using new TableView(context) instead of XML since I'm embedding it in a compose AndroidView.

lupaulus commented 3 years ago

Hi Did you find any solution to this problem? I noted that the click is register inside the library RecyclerView but the listener is not working.

The logs when I click on a Cell:

D/VerticalRecyclerViewListener: mCellRecyclerView scroll listener added
D/HorizontalRecyclerViewListener: Scroll listener  has been added to 0 at action down
D/VerticalRecyclerViewListener: mCellRecyclerView scroll listener removed from up 
D/HorizontalRecyclerViewListener: Scroll listener  has been removed to 0 at action up
D/VerticalRecyclerViewListener: mCellRecyclerView scroll listener added
D/HorizontalRecyclerViewListener: Scroll listener  has been added to 0 at action down
D/VerticalRecyclerViewListener: mCellRecyclerView scroll listener removed from up 
D/HorizontalRecyclerViewListener: Scroll listener  has been removed to 0 at action up
lupaulus commented 3 years ago

I will add this to documentation

app:allow_click_inside_cell="true"
app:allow_click_inside_row_header="true"
app:allow_click_inside_column_header="true"
davidwong commented 3 years ago

As a temporary work around, I copied the source code for TableView to create my own table view class that has an extra constructor where you can pass in the boolean values to set those flags. This has to done in a constructor since those boolean flags are private. Note that for this to work, I also had to copy and change the code for the PreferencesHandler class, since that was hardcoded to accept a TableView in it's constructor, instead of the ITableView interface like most of the other internal dependencies. The only change there was in the constructor to accept my table view class instead of TableView.