Shortcuts Flashcards
Run app in emulator
Shift F10
Save all
Cntl S
Comment 1 line
Ctnl /
Comment multi lines
Ctnl Shift /
Create function on custom method name()
Alt Shift Enter
Reformat all selected code
Cntl Alt L
What do the sizes mean sp vs dp
Sp = Scalable Pixels, text size is 36sp
Dp = Density Pixels, layout size
How do you import images?
Resource manager > [+] > import Drawables
How do you auto write the include libraries when you add code?
File > Settings > Editor > General > Auto import
Include a val in text string?
Add $ before Val
E.g. “Your ${valName.funName} rest of text”
Add param to a function. Int?
fun name(val nums: Int) {}
Find item by resource ID?
val textValue = findViewById(R.string.string_name)
val myButton: Button = findViewById(R.id.button)
How donyou set up a button click?
setOnClickListener
myButton.setOnClickListener { }
Set text on a text view?
myTextView.text = “new text”
Structure of if?
val num = 4 if (num > 4) { X } else if (num == 4) { Y } else { Catch all }