You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 14, 2018. It is now read-only.
I often create companion methods for Fragments that create new instance of the fragment and a helper to initialise arguments for that new instance is really helpful, e.g.:
class MyFragment : Fragment() {
companion object {
const val LABEL = "label"
const val INDEX = "index"
fun newInstance(label: String, value: Int): PostFragment {
return MyFragment().withArguments {
putString(LABEL, label)
putInt(INDEX, index)
}
}
}
}
Possible implementation
inline fun <T: Fragment> T.withArguments(block: Bundle.() -> Unit): T
= this.apply { arguments = Bundle().apply(block) }
I often create companion methods for Fragments that create new instance of the fragment and a helper to initialise arguments for that new instance is really helpful, e.g.:
Possible implementation