Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BasicFragment : Fragment() {
- private var listener: LoopFragment.OnFragmentInteractionListener? = null
- override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
- savedInstanceState: Bundle?): View? {
- val view = inflater.inflate(R.layout.fragment_basic, container, false)
- val button1 = view.findViewById<Button>(R.id.button1)
- button1.setOnClickListener {
- onButtonPressed("Basic Fragment")
- }
- return view
- }
- override fun onAttach(context: Context) {
- super.onAttach(context)
- if (context is OnFragmentInteractionListener) {
- listener = context
- } else {
- throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")
- }
- }
- override fun onDetach() {
- super.onDetach()
- listener = null
- }
- fun onButtonPressed(str: String) {
- listener?.onFragmentInteraction(str)
- }
- interface OnFragmentInteractionListener {
- fun onFragmentInteraction(str: String)
- }}
Add Comment
Please, Sign In to add comment