Tablayout / Viewpager2 사용 템플릿 - Clicklistener
액티비티에서 사용할때와 프래그먼트에서 사용할 때의 차이점 : FragmentStateAdapter(fg)에 들어가는 인자가 다르다.
Activity는 FragmentActivity를 사용하고, Fragment에서는 Fragment인자를 넣어야한다.
액티비티.
프래그먼트에서.
1. OncreatedView 같은 부분에서
//m31VpHistory = m31_vp2_history_option
// val pagerAdapter = M31F0VpAdapter(this,2)
// m31VpHistory.adapter = pagerAdapter
//
// m31_tab_history_select.tabRippleColor = null
// TabLayoutMediator(m31_tab_history_select, m31VpHistory)
// {
// tab, position ->
// if (position ==0)
// {
// tab.text = "작성 글"
// }
// else tab.text = "댓글"
// }.attach()
2. 클래스 생성
// private inner class M31F0VpAdapter(fg : Fragment, itemCount : Int) : FragmentStateAdapter(fg){
// val count = itemCount
// override fun getItemCount(): Int {
// return count
// }
//
// override fun createFragment(position: Int): Fragment {
// return when(position){
// 0->{
// M312PostingHistory()
// }
// 1-> {
// M312CommentHistory()
// }
//
// else -> M312CommentHistory()
// }
// }
// }
클릭이벤트 구현 예제