Not displayed View on TabLayout when using anko. what's wrong?


#1

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val coordinatorLayout = this.coordinatorLayout {
lparams(matchParent, matchParent)

appBarLayout {
lparams(matchParent, wrapContent)

val myTabLayout = themedTabLayout(R.style.ThemeOverlay_AppCompat_Dark) {
lparams(matchParent, wrapContent)
{
tabGravity = Gravity.FILL
tabMode = TabLayout.MODE_FIXED
}
}
val ContentViewPager = viewPager {
id = View.generateViewId()
adapter = MyAdapter(this@MainActivity, this@MainActivity.supportFragmentManager)
}

myTabLayout.setupWithViewPager(ContentViewPager)
}
}
}

class ResFragment( ) : android.support.v4.app.Fragment ( ) {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?
{
val r = TextView(container?.context )
r.text = “dfdfdff”

container?.addView®
return r//ResView().createView(AnkoContext.Companion.create(inflater.context, this, false))
}
}

data class MyAdapter( val MainAct: MainActivity , val fm: android.support.v4.app.FragmentManager) : FragmentPagerAdapter(fm) {

val v1 = ResFragment()
val v2 = ResFragment()
val v3 = ResFragment()

override fun getItem(position: Int): android.support.v4.app.Fragment {
return when (position) {
0 -> v1
1 -> v2
else -> v3
}
}

override fun getCount(): Int {
// Show 2 total pages.
return 2
}

override fun getPageTitle(position: Int): CharSequence? {
when (position) {
0 -> return “111”
1 -> return “222”
else -> return “???”
}
return null
}
}
}