0
0
Android Kotlinmobile~10 mins

First Android app in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to display a simple text in the app's main screen.

Android Kotlin
setContentView(R.layout.[1])
Drag options to blanks, or click blank then click option'
Aactivity_main
Bmain_activity
Clayout_main
Dmain_layout
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong layout file name.
Confusing the layout resource with other resource types.
2fill in blank
medium

Complete the code to find a TextView by its ID and set its text.

Android Kotlin
val textView = findViewById<TextView>(R.id.[1])
textView.text = "Hello, Android!"
Drag options to blanks, or click blank then click option'
Amain_text
BtextView
Chello_text
Dtext_view
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase instead of snake_case for IDs.
Using the wrong ID name.
3fill in blank
hard

Fix the error in the code to correctly set the text of a TextView.

Android Kotlin
val textView = findViewById<TextView>(R.id.text_view)
textView.[1] = "Welcome!"
Drag options to blanks, or click blank then click option'
Atext
BsetText
Cset_text
DText
Attempts:
3 left
💡 Hint
Common Mistakes
Using Java style setText() method in Kotlin.
Using incorrect property names.
4fill in blank
hard

Fill both blanks to create a button click listener that changes the TextView text.

Android Kotlin
val button = findViewById<Button>(R.id.button)
button.setOnClickListener {
    val textView = findViewById<TextView>(R.id.[1])
    textView.[2] = "Button clicked!"
}
Drag options to blanks, or click blank then click option'
Atext_view
BsetText
Ctext
Dbutton_text
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong ID for the TextView.
Using Java style setText() instead of Kotlin property.
5fill in blank
hard

Fill all three blanks to create a simple app that updates a TextView when a button is clicked.

Android Kotlin
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.[1])

        val button = findViewById<Button>(R.id.[2])
        button.setOnClickListener {
            val textView = findViewById<TextView>(R.id.[3])
            textView.text = "Clicked!"
        }
    }
}
Drag options to blanks, or click blank then click option'
Aactivity_main
Bbutton
Ctext_view
Dmain_activity
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up layout and view IDs.
Forgetting to set the content view before finding views.