Created
October 21, 2017 19:14
-
-
Save EmmanuelGuther/1fde5cfbd1cdcd21cd852e3bb5716e02 to your computer and use it in GitHub Desktop.
An example to how implements a button Onclick in Kotlin - Android Fragment
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 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 -> { | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much !