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

前端 未结 5 1761
情歌与酒
情歌与酒 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:43

    Both works the same way.

    Java Convention

    textView.setText(“…”)
    

    Kotlin Convention

    textView.text=”…”
    

    “Methods that follow the Java conventions for getters and setters (no-argument methods with names starting with get and single-argument methods with names starting with set) are represented as properties in Kotlin.”- documentation

    thus textView.text=”…” instead of textView.setText(“…”) if you are using Kotlin to follow Kotlin Conventions.

    Ref - Begin Kotlin; from an Activity, a Button and a TextView

提交回复
热议问题