Mercurial > dwindows
changeset 2692:231f9489a38a
Android: Keep a list of tab titles in the ViewPager2 adapter and set titles in
the TabLayoutMediator, since they seem to get reset in the data change handler.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 31 Oct 2021 23:36:33 +0000 |
parents | e13607b87517 |
children | 0dac724f890f |
files | android/DWindows.kt |
diffstat | 1 files changed, 7 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/android/DWindows.kt Sun Oct 31 21:22:11 2021 +0000 +++ b/android/DWindows.kt Sun Oct 31 23:36:33 2021 +0000 @@ -91,6 +91,7 @@ class DWTabViewPagerAdapter : RecyclerView.Adapter<DWTabViewPagerAdapter.DWEventViewHolder>() { val viewList = mutableListOf<LinearLayout>() val pageList = mutableListOf<Long>() + val titleList = mutableListOf<String?>() var currentPageID = 0L var recyclerView: RecyclerView? = null @@ -2219,7 +2220,8 @@ pager.id = View.generateViewId() pager.adapter = DWTabViewPagerAdapter() TabLayoutMediator(tabs, pager) { tab, position -> - // This code never gets called? + val adapter = pager.adapter as DWTabViewPagerAdapter + tab.text = adapter.titleList[position] }.attach() var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h) @@ -2290,10 +2292,12 @@ if (front != 0) { adapter.viewList.add(0, placeholder) adapter.pageList.add(0, pageID) + adapter.titleList.add(0, null) tabs.addTab(tab, 0) } else { adapter.viewList.add(placeholder) adapter.pageList.add(pageID) + adapter.titleList.add(null) tabs.addTab(tab) } adapter.notifyDataSetChanged() @@ -2338,6 +2342,7 @@ if (tab != null) { adapter.viewList.removeAt(index) adapter.pageList.removeAt(index) + adapter.titleList.removeAt(index) tabs.removeTab(tab) adapter.notifyDataSetChanged() } @@ -2366,6 +2371,7 @@ if (tab != null) { tab.text = text + adapter.titleList[index] = text } notebookCapsOff(tabs)