Header Text and Sort Indicators Not Shown on API 16 or 17
See original GitHub issueUnfortunately I don’t have any physical devices running these versions of Android, so I’m not able to test whether the problem is somehow related to running in the emulator. The problem isn’t present API 18 (4.3) or above (which I’ve tested both physically and virtually).
I removed all modifications to the color/styling, and the problem still persists. The header has the usual height and width, but it is as if there are simply no columns:
In the constructor of my subclass of SortableTableView
, I set the header adapter as follows:
SimpleTableHeaderAdapter header = new SimpleTableHeaderAdapter(context, /* omitted */);
setHeaderAdapter(header);
The XML for the table view is:
</*package*/.TransactionsTableView
android:id="@+id/trans_table"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tableView_columnCount="4"
/>
Do you know of any issues with the library on these versions of Android?
Edit 1: It looks like this may be related to my previous bug report. The headers are only invisible when they are created while the view is initially hidden - so the sample app worked fine on APIs 16 & 17. I also copied my table into a plain activity with no fragments-and-viewpager going on, and the headers worked there as well.
Edit 2: Here is my hacky workaround to invalidate the header when the fragment becomes visible:
@Override
public void setMenuVisibility(boolean menuVisible)
{
super.setMenuVisibility(menuVisible);
if (menuVisible && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2)
{
try
{
Field f = SortableTableView.class.getDeclaredField("sortableTableHeaderView");
f.setAccessible(true);
LinearLayout header = (LinearLayout) f.get(mTableView);
header.invalidate();
}
catch (NoSuchFieldException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
}
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
The problem seems to be with the line https://github.com/ISchwarz23/SortableTableView/blob/master/tableview/src/main/java/de/codecrafters/tableview/TableHeaderView.java#L74 When getWidth() is called the layout has not been done hence the width returned is 0.
Adding the LayoutChangeListener on https://github.com/ISchwarz23/SortableTableView/blob/master/tableview/src/main/java/de/codecrafters/tableview/TableHeaderView.java#L39 should somehow fix this but for some reason it’s not working.
The workaround that has worked for me is using the tree observer to know when the layout has been done so that I can set the header adapter.
Hi @ISchwarz23 The issue I was having does not appear when using the new version. I am curious to know what the problem was, since after going through the changes in the new version, I see no changes (or maybe I missed something) directly touching on the issue I was having.