Skip to content

Instantly share code, notes, and snippets.

@pokk
Created January 13, 2017 07:51
Show Gist options
  • Save pokk/2ea715c6ae085b4328d52dfd77c6b800 to your computer and use it in GitHub Desktop.
Save pokk/2ea715c6ae085b4328d52dfd77c6b800 to your computer and use it in GitHub Desktop.
using kotlin language in new instance.

Introduction

New a fragment instance in Kotlin style.

class MyFragment: BaseFragment() {
companion object Factory {
// The key name of the fragment initialization parameters.
private val ARG_PARAM_: String = "param_"
fun newInstance(arg1: String? = null):
MovieGalleryFragment = MovieGalleryFragment().apply {
this.arguments = Bundle().apply {
this.putString(ARG_PARAM_, arg1)
}
}
}
// Get the arguments from the bundle here.
private val arg: String by lazy { this.arguments.getString(ARG_PARAM_) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment