• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Tab switching delays during Webservice execution android TabLayout

I am using a TabLayout that displays 3 Tabs. When the app is launched First Tab makes Webservice API call,I am not able to move to second tab until first tab First screen finishes Webservice call execution. Is there a way I can stop my First Tab execution when clicked on 2ndTab .

My Code for TabLaylaout

Code:
<ui_components.CustomTabLayout
       android:id="@+id/sliding_tabs"
       style="[USER=19691]@Style[/USER]/tab_style"
       android:layout_width="match_parent"
       app:tabMode="scrollable"
       />

CustomTabLayout:

class CustomTabLayout : TabLayout {
   constructor(context: Context) : super(context) {}
   constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {}
   constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
       context,
       attrs,
       defStyleAttr
   ) {
   }

   override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
       val tabLayout: ViewGroup = getChildAt(0) as ViewGroup
       val childCount: Int = tabLayout.childCount
       if (childCount != 0) {
           val displayMetrics: DisplayMetrics = context.resources.displayMetrics
           val tabMinWidth: Int = displayMetrics.widthPixels / childCount
           for (i in 0 until childCount) {
               tabLayout.getChildAt(i).minimumWidth = tabMinWidth
           }
       }
       super.onMeasure(widthMeasureSpec, heightMeasureSpec)
   }
}
 
Last edited by a moderator:

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones