What is the difference between textView.setText(string) and textView.text = $string

前端 未结 5 1721
情歌与酒
情歌与酒 2021-01-20 03:46

Hi I am making a app with Kotlin and I found that I can both use

textView.setText(str)

and

textView.text =         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-20 04:23

    As in the Kotlin, you are not using findViewById

    so to access your textView, import statement must be like this

    import kotlinx.android.synthetic.main..*
    

    And textView.text = $str is the Synthetic Property access provided by Kotlin Plugin for android

    You can use both, not much difference in the usability, but for the easier code writing this would be better

    For more information, read this https://kotlinlang.org/docs/tutorials/android-plugin.html

提交回复
热议问题