Created
November 29, 2020 15:39
-
-
Save BuiVanNam/605fd9a8f3ac6f52f1c36d6096dd7e94 to your computer and use it in GitHub Desktop.
Scope Functions
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
//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