• 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:
I added code tags for readability. :)
Code Tag Usage:
[code]Line 1
Line 2
Line 3
Maintains white space
Doesn't turn :) into emoji
etc...
[/code]

Code:
Line 1
Line 2
Line 3
Maintains white space
Doesn't turn :) into emoji
etc...
 
Back
Top Bottom