Found 417 Articles for Kotlin

How to make an Android Spinner with initial default text using Kotlin?

Azhar
Updated on 28-Nov-2020 12:11:03

818 Views

This example demonstrates how to make an Android Spinner with initial default text using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.view.View import android.widget.AdapterView import android.widget.AdapterView.OnItemSelectedListener import android.widget.ArrayAdapter import android.widget.Spinner import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var spinner: Spinner    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)   ... Read More

How do I send an object from one Android Activity to another using Intents in Kotlin?

Azhar
Updated on 28-Nov-2020 11:58:05

478 Views

This example demonstrates how to send an object from one Android Activity to another using Intents in Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒   New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.ktimport android.content.Intent import android.os.Bundle import android.widget.Button import android.widget.EditText import androidx.appcompat.app.AppCompatActivity import java.io.Serializable class MainActivity : AppCompatActivity() {    lateinit var editText: EditText    lateinit var button: Button    override fun onCreate(savedInstanceState: Bundle?) {     ... Read More

How to check internet connection availability and the network type on Android using Kotlin?

Azhar
Updated on 28-Nov-2020 11:49:26

888 Views

This example demonstrates how to check internet connection availability and the network type on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.content.Context import android.net.ConnectivityManager import android.os.Bundle import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var textView: TextView    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)   ... Read More

How do I load an ImageView by URL on Android using kotlin?

Azhar
Updated on 28-Nov-2020 11:43:48

3K+ Views

This example demonstrates how to load an ImageView by URL on Android using kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.annotation.SuppressLint import android.graphics.Bitmap import android.graphics.BitmapFactory import android.os.AsyncTask import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log import android.widget.ImageView import android.widget.Toast class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       ... Read More

How do I pass an object from one activity to another on Android using Kotlin?

Azhar
Updated on 28-Nov-2020 11:37:54

1K+ Views

This example demonstrates how to pass an object from one activity to another on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.content.Intent import android.os.Bundle import android.widget.Button import androidx.appcompat.app.AppCompatActivity import java.io.Serializable; class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"     ... Read More

How to get fling gesture detection working in an Android App using Kotlin?

Azhar
Updated on 28-Nov-2020 11:29:07

404 Views

This example demonstrates how to get fling gesture detection working in an Android App using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.view.GestureDetector import android.view.MotionEvent import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity(), GestureDetector.OnGestureListener{    lateinit var gestureDetector: GestureDetector    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title ... Read More

How to get the current GPS location programmatically on Android using Kotlin?

Azhar
Updated on 28-Nov-2020 11:24:20

8K+ Views

This example demonstrates how to get the current GPS location programmatically on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.Manifest import android.content.Context import android.content.pm.PackageManager import android.location.Location import android.location.LocationListener import android.location.LocationManager import android.os.Bundle import android.widget.Button import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat class MainActivity : AppCompatActivity(), LocationListener {    private lateinit var locationManager: LocationManager ... Read More

The simplest way to get the user's current location on Android using Kotlin?

Azhar
Updated on 28-Nov-2020 11:17:32

951 Views

This example demonstrates how to get the user's current location on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Add the following dependency in Gradleimplementation 'com.google.android.gms:play-services-location:17.0.0'Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.Manifest import android.content.Intent import android.content.pm.PackageManager import android.location.Geocoder import android.location.Location import android.os.Bundle import android.os.Handler import android.os.ResultReceiver import android.util.Log import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import com.google.android.gms.location.* class MainActivity ... Read More

How do I declare global variables on Android using Kotlin?

Azhar
Updated on 28-Nov-2020 11:06:04

4K+ Views

This example demonstrates how to declare global variables on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var textView: TextView    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       textView = findViewById(R.id.text) ... Read More

How to get screen dimensions in pixels on Android App using Kotlin?

Azhar
Updated on 28-Nov-2020 11:02:01

1K+ Views

This example demonstrates how to get screen dimensions in pixels on the Android App using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.util.DisplayMetrics import android.view.WindowManager import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var tvHeight: TextView    lateinit var tvWidth: TextView    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)   ... Read More

Advertisements