Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EmmanuelGuther/1fde5cfbd1cdcd21cd852e3bb5716e02 to your computer and use it in GitHub Desktop.
Save EmmanuelGuther/1fde5cfbd1cdcd21cd852e3bb5716e02 to your computer and use it in GitHub Desktop.
An example to how implements a button Onclick in Kotlin - Android Fragment
class ExmpleFragment : Fragment(), View.OnClickListener {
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View = inflater!!.inflate(R.layout.fragment, container, false)
val btn: Button = view.find(R.id.button2)
btn.setOnClickListener(this)
return view
}
companion object {
fun newInstance(): ExampleFragment {
return ExampleFragment()
}
}
override fun onClick(v: View?) {
when (v?.id) {
R.id.button2 -> {
toast("alpjasjdkasndknaskdnkasndkasndkjnaskjdnaskjdnkasjndkas")
}
else -> {
}
}
}
}
@MarioIoannou
Copy link

Lifesaver!!!!

@Pikl6000
Copy link

Thank you so much !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment