An Interest In:
Web News this Week
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
- March 14, 2024
February 22, 2022 11:25 pm GMT
Original Link: https://dev.to/ubergamz/freshly-learned-kotlin-techniques-omf
Freshly Learned Kotlin Techniques
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. Ill leave an example of how to change a picture.
val carPicture = findViewById<ImageView>(R.id.carPicture)carPicture.setImageResource(R.drawable.car_one_detail)
Original Link: https://dev.to/ubergamz/freshly-learned-kotlin-techniques-omf
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To