Skip to content

Instantly share code, notes, and snippets.

@Taishi-Y
Created December 22, 2017 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Taishi-Y/5618ea63c4baa9a37b08bfca157080b0 to your computer and use it in GitHub Desktop.
Save Taishi-Y/5618ea63c4baa9a37b08bfca157080b0 to your computer and use it in GitHub Desktop.
TypicalViewPagerAdapterTemplate
import android.content.Context
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
/**
* Created by taishi-y on 2017/12/20
*/
class ${NAME}(fm: FragmentManager, val context: Context) : FragmentPagerAdapter(fm) {
override fun getItem(position: Int): Fragment = when(position) {
0 -> ExampleFragment.newInstance()
1 -> ExampleFragment.newInstance()
else -> throw IllegalArgumentException("fragment not found")
}
override fun getPageTitle(position: Int): CharSequence = when(position) {
0 -> context.resources.getString(R.string.example_title)
1 -> context.resources.getString(R.string.example_title)
else -> throw IllegalArgumentException("title not found")
}
override fun getCount(): Int = 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment