Closed WhoisAbel closed 3 years ago
Previously, you learned that there are types of data like Int for integer numbers and String for text. IntRange is another data type, and it represents a range of integer numbers from a starting point to an endpoint.
val diceRange = 1..6
You can call functions directly on a range, for example: (1..6).random().
With this class, you have a blueprint of object in real world .
Classes are like a blueprint of an object. They can have properties and behaviors, implemented as variables and functions.
When there are Views within a ViewGroup, the Views are considered children of the parent ViewGroup. In the case of your app, the TextView and Button would be considered children of the parent ConstraintLayout.
An Activity provides the window in which your app draws its UI. Typically, an Activity takes up the whole screen of your running app. Every app has one or more activities. The top-level or first activity is often called the MainActivity and is provided by the project template.
On macOS, open the settings by going to File > Settings > Editor > General > Auto Import. for New Projects... Expand Other Settings > Auto Import. In the Java and Kotlin sections, make sure Add unambiguous imports on the fly and Optimize imports on the fly (for current project) are checked. Note that there are two checkboxes in each section. Save the changes and close settings by pressing OK.
The unambiguous imports settings tell Android Studio to automatically add an import statement, as long as it can determine which one to use. The optimize imports settings tell Android Studio to remove any imports that aren't being used by your code.
Android automatically assigns ID numbers to the resources in your app. For example, the Roll button has a resource ID, and the string for the button text also has a resource ID. Resource IDs are of the form R.
Use the rollButton object and set a click listener on it by calling the setOnClickListener() method. Instead of the parentheses following the method name, you will actually be using curly braces following the method name. This is a special syntax for declaring a Lambda,
Use setImageResource() to change the image that's displayed in an ImageView
Learn more concepts in Kotlin—including classes, objects, and conditionals—to create an interactive app for your users.