Recently, the get/set methods have been making more sense.
In Android Studio, in the XML pages (activity) you can create an object. Once you give it a name, you can start some code in the .kt side
Like all variables before you change them, objects too have to be defined.
[val or var] [name of string you want to create] : [type of object] = findViewById (R.id.[the id name you created in the XML page])
Once you call it, you can set it.
[string name you created].[type of input you are going to change] = [value]
Example below for the most used type, TextView
val strengthText: TextView = findViewById(R.id.strengthText)
strengthText.text = "Strength"
There are other types and methods, but they all follow the same pattern. I’ll leave an example of how to change a picture.
val carPicture = findViewById<ImageView>(R.id.carPicture)
carPicture.setImageResource(R.drawable.car_one_detail)
Top comments (0)