Categories
Android

What is a Kotlin data class?

In Java, we had to often make classes for our data models. A Kotlin equivalent would be something like this: But now in Kotlin we have data classes, like this: We can create it from MainActivity.kt with this: Accessing data is easy: No need for setFirstName, setLastName or getAge. Simply call person.firstName, person.age, etc. A […]

Categories
Android

How to get GPS coordinates

Fetching the longitude and latitude on Android devices isn't hard. In this tutorial we'll get the GPS location of our Android phone, tablet or emulator. Let's begin! This tutorial uses Kotlin, the preferred language of Google and myself. Open AndroidManifest.xml (inside the app -> manifest folder), then add the required permission for getting the location. […]

Categories
Android

How to add rounded corners to buttons

Making rounded corners to a Button widget can add a nice touch to your UI. Fortunately, rounded corners aren't that hard to make. Let's begin! Right click on the drawable folder and select New -> Drawabe resource folder. Then name the drawable image custom_rounded_corners. Write the following code into the editor, then open the Preview […]

Categories
Android

Build a RecyclerView in Kotlin

Creating a RecyclerView in Kotlin isn't that hard. With some guidance, and a little effort, you too can create a RecyclerView. In this tutorial, we'll use ConstraintLayout, Kotlin and Android Studio to build it. First, open Android Studio and create a new project. Then select the following. Then select Kotlin and androidx, then hit finish. […]

Categories
Personal

Jason's Deli

Categories
Android

Replacing findViewById with Kotlin synthetic imports

Old way: New way: This is possible because of Kotlin synthetic imports. Just type the TextView's id, that's it. Just make sure the TextView has an ID that matches the Kotlin code. For clarity, here is the Kotlin import: This is another way Kotlin allows developers to do more when less code. I've used Kotlin […]

Categories
Android

Baby Kevin at H-E-B Digital