This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var button: Button = findViewById(R.id.button) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Sample 1 | |
private var button: Button = findViewById(R.id.button) | |
//Sample 2 | |
private var button: Button? = null | |
private fun init(){ button = findViewById(R.id.button) } | |
//Sample 3 (The lateinit keyword stands for late initialization. lateinit modifier is allowed only on mutable properties) | |
private lateinit var button:Button | |
private fun init(){ button = findViewById(R.id.button) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
private val foodList = arrayListOf("Pizza", "Chiness", "Hamburger", "McDonalds") | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
button_decide.setOnClickListener { | |
val randomFood = Random().nextInt(foodList.count()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
val initialTextViewTranY = textView_progress.translationY | |
seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { | |
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { | |
textView_progress.text = progress.toString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
android:layout_width="match_parent" |