Guest User

Untitled

a guest
Jun 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import android.support.v4.app.Fragment
  2. import org.jetbrains.anko.bundleOf
  3.  
  4. /**
  5. * Pass arguments to a Fragment without the hassle of
  6. * creating a static newInstance() method for every Fragment.
  7. *
  8. * Declared outside any class to have full access in any
  9. * part of your package.
  10. *
  11. * Usage: instanceOf<MyFragment>("foo" to true, "bar" to 0)
  12. *
  13. * @return Returns an instance of Fragment as the specified generic type with the params applied as arguments
  14. */
  15. inline fun <reified T : Fragment> instanceOf(vararg params: Pair<String, Any>)
  16. = T::class.java.newInstance().apply {
  17. arguments = bundleOf(*params)
  18. }
Add Comment
Please, Sign In to add comment