What is it?
Random Trivia is a simple quiz app developed in Kotlin. The user plays a short game of 2 out of 3 trivia. There are a total of 10 random trivia questions that could be shown. From those 10, 3 are randomly selected and displayed one by one to the player. The player can choose one of three answer choices by clicking the corresponding letter button, ‘A’, ‘B’, or ‘C’. If the player gets two or more answers correct, then they win. Otherwise, they lose. The total number of correct answers is displayed in the top left corner of the screen and is updated as the game progresses. After the game, the user can press the play again button to play the game again.
The Development Process
This was my first time working with Kotlin. It was pretty fun, although I did feel like a part of me was missing every time I wrote a line of code and didn’t put a semicolon at the end. It was also a bit odd not using the new keyword at all. It was also a bit weird creating an Intent because to get the class in Kotlin you need to add ::class.java to the end of the Activity name. Overall, it was really fun to program in Kotlin and I’ll definitely be playing around with it some more.
It didn’t occur to me until just now, but I should probably do these mini projects on GitHub since I can make the code public. I’ll be doing that from now on. One of my favorite things about Kotlin from the little I’ve played with it is that you can directly access UI elements by id in the code without creating a variable for it. For example, in Java you need to declare a TextView variable and assign the TextView element by it’s id to that variable. However in Kotlin, you can just type the element’s id and then do whatever you were planning on doing directly to the element without needing to save it in a variable. For example,
TextView exampleText = findViewById(R.id.exampleTextView); exampleText.setText(“Hello World!”);
in Java becomes
in Kotlin. It’s really neat and I love it.