Newer
Older
MonCalc / app / src / main / kotlin / jackall / moncalc / adapter / MainFragmentPagerAdapter.kt
package jackall.moncalc.adapter

import android.content.Context
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import jackall.moncalc.R
import jackall.moncalc.fragment.FruitAnalyze
import jackall.moncalc.fragment.HistoryFragment
import jackall.moncalc.fragment.TempleAnalyze

/**
 * Created by matsumoto_k on 2017/11/03.
 */
class MainFragmentPagerAdapter(fragmentManager: FragmentManager, val context: Context) : FragmentPagerAdapter(fragmentManager) {
    val pageCount = 3
    val titles = arrayOf(context.resources.getString(R.string.history), context.resources.getString(R.string.temple_analyze), context.resources.getString(R.string.fruit_analyze))
    val historyFragment by lazy { HistoryFragment() }
    val templeAnalyzeFragment by lazy { TempleAnalyze() }
    val fruitAnalyzeFragment by lazy { FruitAnalyze() }
    override fun getItem(position: Int): Fragment? {
        when (position) {
            0 -> return historyFragment
            1 -> return templeAnalyzeFragment
            2 -> return fruitAnalyzeFragment
        }
        return null
    }

    override fun getCount(): Int {
        return pageCount
    }

    override fun getPageTitle(position: Int): CharSequence {
        return titles.get(position)
    }
}