Skip to content

Instantly share code, notes, and snippets.

@BuiVanNam
Created November 29, 2020 15:39
Show Gist options
  • Save BuiVanNam/605fd9a8f3ac6f52f1c36d6096dd7e94 to your computer and use it in GitHub Desktop.
Save BuiVanNam/605fd9a8f3ac6f52f1c36d6096dd7e94 to your computer and use it in GitHub Desktop.
Scope Functions
//Not use Scope Functions
fun updateTextView(parentView: View) {
val textView = parentView.findViewById<TextView>(R.id.text_view)
if (textView != null) {
textView.text = "nambv"
textView.setTextColor(Color.RED)
textView.textSize = 15f
textView.maxLines = 1
textView.gravity = Gravity.CENTER
}
}
//Use Scope Functions
fun updateTextViewUseScopeFuntions(parentView: View) {
parentView.findViewById<TextView>(R.id.text_view)?.run {
text = "nambv"
setTextColor(Color.RED)
textSize = 15f
maxLines = 1
gravity = Gravity.CENTER
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment