android-viewpager

How does fragment's lifecycle works inside viewpager? Why onStop is not called on navigation change?

被刻印的时光 ゝ 提交于 2020-04-16 05:42:38
问题 I'm using ViewPager 2 from AndroidX with 4 instances of the same fragment. My question is pretty straight forward. When I'm navigating to some another fragment(using navigation drawer or even something else). OnStop() , OnDestroy(), OnDettach() of the fragments inside the viewpager does not gets triggered. So why is that? And If I want to remove the listeners I've started already, in one of these methods, how can I do that? For example, I'm using GreenRobot's EventBus. And I'm registering the

How does fragment's lifecycle works inside viewpager? Why onStop is not called on navigation change?

只谈情不闲聊 提交于 2020-04-16 05:42:24
问题 I'm using ViewPager 2 from AndroidX with 4 instances of the same fragment. My question is pretty straight forward. When I'm navigating to some another fragment(using navigation drawer or even something else). OnStop() , OnDestroy(), OnDettach() of the fragments inside the viewpager does not gets triggered. So why is that? And If I want to remove the listeners I've started already, in one of these methods, how can I do that? For example, I'm using GreenRobot's EventBus. And I'm registering the

How to change selected tab title textSize in Android

孤人 提交于 2020-04-11 07:48:43
问题 I am trying to find a way to change text size of Tab Title when selected. Until now without exit. Hope someone can help me. My code bellow: XML : <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" android

remove fragment in viewPager2 use FragmentStateAdapter, but still display

北战南征 提交于 2020-04-11 07:41:41
问题 I have a viewPager2 and FragmentStateAdapter, and there are Fragement1, 2,3 4, I am in fragment2, and want to remove fragment3, and display fragment4 after fragment2. The problem is it always show me fragment3(data), the debug shows the fragment3 has been removed, but the displayed page still has fragment3 content. Adpter: class TipsAdapter( private val items: MutableList<TripPage>, context: FragmentActivity ) : FragmentStateAdapter(context) { private val fragmentFactory = context

remove fragment in viewPager2 use FragmentStateAdapter, but still display

依然范特西╮ 提交于 2020-04-11 07:41:32
问题 I have a viewPager2 and FragmentStateAdapter, and there are Fragement1, 2,3 4, I am in fragment2, and want to remove fragment3, and display fragment4 after fragment2. The problem is it always show me fragment3(data), the debug shows the fragment3 has been removed, but the displayed page still has fragment3 content. Adpter: class TipsAdapter( private val items: MutableList<TripPage>, context: FragmentActivity ) : FragmentStateAdapter(context) { private val fragmentFactory = context

Get current fragment with ViewPager2

与世无争的帅哥 提交于 2020-04-07 17:42:32
问题 I'm migrating my ViewPager to ViewPager2 since the latter is supposed to solve all the problems of the former. Unfortunately, when using it with a FragmentStateAdapter , I don't find any way to get the currently displayed fragment. viewPager.getCurrentItem() gives the current displayed index and adapter.getItem(index) generally creates a new Fragment for the current index. Unless keeping a reference to all created fragments in getItem() , I have no idea how to access the currently displayed

ViewPager with two tabs causes IndexOutOfBoundsException when sliding and clicking

放肆的年华 提交于 2020-04-03 10:41:05
问题 I have two tabs in which I add two different lists of data, both tabs share a single recyclerview, so at my viewpager adapter, I just create a new instance to populate the data From the View val allProducts = completeProductList val productsList = mutableListOf<Products>() val drinksList = mutableListOf<Products>() for (product in allProducts) { if (product.isDrink) { drinksList.add(product) } else { productsList.add(product) } } viewPagerAdapter.productsList = productsList viewPagerAdapter

SharedViewModel from viewpager2 and my parent Fragment

不打扰是莪最后的温柔 提交于 2020-03-25 17:56:31
问题 So, I have one fragment, lets call it Fragment A, in which I need it to be the main host of my sharedviewmodel. So I have it like this class FragmentA:Fragment() { private val model: SharedViewModel by viewModels() } Now, inside Fragment A, I set viewpager2 Adapter private fun setupViewPagerWithTabLayout( productList: MutableList<Producto>, drinkList: MutableList<Producto> ) { val fragmentList = listOf( FragmentProducts.newInstance(productList), FragmentProducts.newInstance(drinkList))

No view found for id 0x7f0800c4 for fragment

旧街凉风 提交于 2020-03-05 04:41:07
问题 I get this error when I am trying to replace the parent fragment ( SearchFragment ) from the child fragment ( ClassroomsTab ) in a swipe tab viewPager . Basically what I am trying to achieve is have a swipe tab menu with multiple buttons in each child fragment that closes the swipe tab menu and open a different existing fragment. The SearchFragment is in a Navigation Drawer activity and so is the destination fragment of the buttons. From what I have read, a solution to this issue is to

Android Vertical View Pager with card stack

不羁的心 提交于 2020-02-23 06:13:32
问题 I am trying to implement a vertical swipeable ViewPager with stack of cards like appearance. I am able to achieve VerticalViewPager using ViewPager.PageTransformer and swapping the touch points. I am getting following card appearance - I want to achieve following appearance - How can I achieve this effect? Thanks in Advance. 回答1: In order to achieve this vertical View Pager without any library dependency You can follow the steps below : In your activity_main.xml <android.support.v4.view