Androiddeveloper_2021
Lurker
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
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: