Created
July 6, 2021 11:08
-
-
Save iamnaran/104a0c2c2dd8311aeee8800808e4aa39 to your computer and use it in GitHub Desktop.
ViewPager2 FragmentState Adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.view.View | |
import android.view.ViewGroup | |
import androidx.fragment.app.Fragment | |
import androidx.fragment.app.FragmentActivity | |
import androidx.viewpager2.adapter.FragmentStateAdapter | |
class ViewPagerAdapter(fa: FragmentActivity, private val listOfTitle: List<String>) : | |
FragmentStateAdapter(fa) { | |
override fun getItemCount(): Int = listOfTitle.size | |
override fun createFragment(position: Int): Fragment { | |
when (position) { | |
0 -> return HomeFragment() | |
1 -> return ProfileFragment() | |
2 -> return NotificationFragment() | |
} | |
return HomeFragment() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment