Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. private const val ARG_PARAM1 = "param1"
  2. private const val ARG_PARAM2 = "param2"
  3.  
  4. class FugaFragment : Fragment() {
  5. private var param1: String? = null
  6. private var param2: String? = null
  7. private var listener: OnFugaFragmentListener? = null
  8. private var fugaText:TextView? = null
  9.  
  10. override fun onCreate(savedInstanceState: Bundle?) {
  11. super.onCreate(savedInstanceState)
  12. arguments?.let {
  13. param1 = it.getString(ARG_PARAM1)
  14. param2 = it.getString(ARG_PARAM2)
  15. }
  16. }
  17.  
  18. override fun onCreateView(
  19. inflater: LayoutInflater, container: ViewGroup?,
  20. savedInstanceState: Bundle?
  21. ): View? {
  22. val view = inflater.inflate(R.layout.fragment_fuga, container, false)
  23.  
  24. fugaText = view.findViewById(R.id.fugaText)
  25.  
  26.  
  27. val displayParams = view.findViewById<Button>(R.id.displayParams)
  28. displayParams.setOnClickListener {
  29. displayParams()
  30. }
  31.  
  32. val finishButton = view.findViewById<Button>(R.id.finishButton)
  33. finishButton.setOnClickListener {
  34. finish()
  35. }
  36. return view
  37. }
  38.  
  39. fun displayParams() {
  40. fugaText?.text = "$ARG_PARAM1: $param1 / $ARG_PARAM2: $param2"
  41. }
  42.  
  43. fun finish() {
  44. listener?.onHugaFragmentFinish()
  45. }
  46.  
  47. override fun onAttach(context: Context) {
  48. super.onAttach(context)
  49. if (context is OnFugaFragmentListener) {
  50. listener = context
  51. } else {
  52. throw RuntimeException("$context must implement OnFugaFragmentListener")
  53. }
  54. }
  55.  
  56. override fun onDetach() {
  57. super.onDetach()
  58. listener = null
  59. println("FugaFragment onDetach")
  60. }
  61.  
  62.  
  63. interface OnFugaFragmentListener {
  64. fun onHugaFragmentFinish()
  65. }
  66.  
  67. companion object {
  68. @JvmStatic
  69. fun newInstance(param1: String, param2: String) =
  70. FugaFragment().apply {
  71. arguments = Bundle().apply {
  72. putString(ARG_PARAM1, param1)
  73. putString(ARG_PARAM2, param2)
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement