I am implementing tabs using TabTemplate but facing issue in refreshing the UI once the tab is clicked. On tab click new screen is loaded where each screen has api call, once api is success I need to refresh the screen. How can we achieve this ?
Code for creating tabs =>
val tabTemplate = TabTemplate.Builder(object : TabCallback {
override fun onTabSelected(tabContentId: String) {
activeContentId = tabContentId
invalidate() //call invalidate() to get the new template to display
}
})
.setHeaderAction(APP_ICON)
tabTemplate.addTab(getTab(firstTab))
tabTemplate.addTab(getTab(secondTab))
tabTemplate.setTabContents(getActiveTabContent())
invalidate()
return tabTemplate.setActiveTabContentId(activeContentId).build()
private fun getActiveTabContent(): TabContents {
return if (activeContentId == firstTab.tabId) {
TabContents.Builder(getFirstTabTemplate()).build()
} else {
TabContents.Builder(getSecondTabTemplate()).build()
}
}
private fun getFirstTabTemplate() : Template {
return FirstScreen(carContext).onGetTemplate()
}
You would need to call invalidate
again after the API call for the given screen has completed.
1