Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
February 22, 2022 11:25 pm GMT

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To