1. Are you ready for the Galaxy S20? Here is everything we know so far!

Tab switching delays during Webservice execution android TabLayout

Discussion in 'Android Development' started by Androiddeveloper_2021, Feb 12, 2021.

  1. Androiddeveloper_2021

    Thread Starter

    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 (Text):
    1. <ui_components.CustomTabLayout
    2.        android:id="@+id/sliding_tabs"
    3.        style="[USER=19691]@Style[/USER]/tab_style"
    4.        android:layout_width="match_parent"
    5.        app:tabMode="scrollable"
    6.        />
    7.  
    8. CustomTabLayout:
    9.  
    10. class CustomTabLayout : TabLayout {
    11.    constructor(context: Context) : super(context) {}
    12.    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {}
    13.    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
    14.        context,
    15.        attrs,
    16.        defStyleAttr
    17.    ) {
    18.    }
    19.  
    20.    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
    21.        val tabLayout: ViewGroup = getChildAt(0) as ViewGroup
    22.        val childCount: Int = tabLayout.childCount
    23.        if (childCount != 0) {
    24.            val displayMetrics: DisplayMetrics = context.resources.displayMetrics
    25.            val tabMinWidth: Int = displayMetrics.widthPixels / childCount
    26.            for (i in 0 until childCount) {
    27.                tabLayout.getChildAt(i).minimumWidth = tabMinWidth
    28.            }
    29.        }
    30.        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
    31.    }
    32. }
     


    #1 Androiddeveloper_2021, Feb 12, 2021
    Last edited by a moderator: Feb 12, 2021

    1. Download the Forums for Android™ app!


      Download

       
  2. Unforgiven

    Unforgiven ...eschew obfuscation...
    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 (Text):
    1. Line 1
    2. Line 2
    3. Line 3
    4. Maintains white space
    5. Doesn't turn :) into emoji
    6. etc...
    7.  
     
    Androiddeveloper_2021 likes this.
Loading...

Share This Page

Loading...