Created
January 16, 2019 18:45
-
-
Save wellingtoncosta/0465344f967e80c3c8e9c33c48c78e66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AwesomeFragment : Fragment() { | |
private var callback: CallbackListener? = null | |
override fun onCreateView( | |
inflater: LayoutInflater, | |
container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? { | |
return inflater.inflate(R.layout.fragment_awesome, container, false) | |
} | |
override fun onActivityCreated(savedInstanceState: Bundle?) { | |
super.onActivityCreated(savedInstanceState) | |
if(activity is CallbackListener) { | |
callback = activity | |
} | |
} | |
override fun onViewCreated(view: View, savedInstance: Bundle?) { | |
super.onViewCreated(view, savedInstance) | |
val button = view.findViewById<Button>(R.id.my_button) | |
button.setOnClickListener { callback?.let { it.onCallback() } } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment