question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Header Text and Sort Indicators Not Shown on API 16 or 17

See original GitHub issue

Unfortunately 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:

blurred

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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
tracerTrescommented, Dec 9, 2016

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.

mTableView = (TableView<String[]>) view.findViewById(R.id.tableView);
ViewTreeObserver vto = mTableView.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                mTableView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                mTableView.setHeaderAdapter(mSimpleTableHeaderAdapter);
            }
        });
0reactions
tracerTrescommented, Jan 21, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tablesort indicator occluded when table header text overflows
The tablesort indicator should always be visible, and never be occluded. Screenshot: screenshot showing visible sort indicator ...
Read more >
jQuery dataTable doesn't show sort icon - Stack Overflow
The problem is that the sort icon (this arrow which point in which direction data is actual sorted) is not displayed. My code...
Read more >
Sort indicator not visible when column header is truncated
Description. If the column size is small enough to truncate the header text, the sort indicator is not visible.
Read more >
When using tables - is it better to show a sort indicator by ...
Now the question is: Is it better to show a sorting indicator by default or only after the user interacted with the column...
Read more >
Notification.Builder | Android Developers
CharSequence) instead to set a text in the header. ... Actions will not be displayed when the notification is collapsed, ... Deprecated in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found