Guest User

Untitled

a guest
Oct 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. class BasicFragment : Fragment() {
  2. private var listener: LoopFragment.OnFragmentInteractionListener? = null
  3.  
  4. override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
  5. savedInstanceState: Bundle?): View? {
  6. val view = inflater.inflate(R.layout.fragment_basic, container, false)
  7. val button1 = view.findViewById<Button>(R.id.button1)
  8. button1.setOnClickListener {
  9. onButtonPressed("Basic Fragment")
  10. }
  11. return view
  12. }
  13.  
  14. override fun onAttach(context: Context) {
  15. super.onAttach(context)
  16. if (context is OnFragmentInteractionListener) {
  17. listener = context
  18. } else {
  19. throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")
  20. }
  21. }
  22.  
  23. override fun onDetach() {
  24. super.onDetach()
  25. listener = null
  26. }
  27.  
  28.  
  29. fun onButtonPressed(str: String) {
  30. listener?.onFragmentInteraction(str)
  31. }
  32.  
  33. interface OnFragmentInteractionListener {
  34. fun onFragmentInteraction(str: String)
  35. }}
Add Comment
Please, Sign In to add comment