This example demonstrates how to use ArrayAdapter in android to create a simple listview 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 MainActivity.ktimport android.os.Bundle import android.widget.ArrayAdapter import android.widget.ListView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" val arrayAdapter: ArrayAdapter ... Read More
This example demonstrates how to use SearchView in the Toolbar 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 − Open res/strings.xml and add the following code− Q38 January February March April May June July August ... Read More
This example demonstrates how to get Spinner value 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 − Open res/strings.xml and add the following code − Q39 crane Cuckoo Pigeon Eagle Owl Vulture WoodPecker Step 4 − Add the ... Read More
This example demonstrates programmatically turning off and turning on WiFi 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 MainActivity.ktimport android.net.wifi.WifiManager import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import android.widget.Toast class MainActivity : AppCompatActivity() { lateinit var wifiManager: WifiManager override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" ... Read More
This example demonstrates how to add Google Search Functionality 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 MainActivity.ktimport android.app.SearchManager import android.content.Intent import android.os.Bundle import android.widget.Button import android.widget.EditText import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { lateinit var editText: EditText lateinit var btnSearch: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ... Read More
This example demonstrates how to integrate Facebook 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 − In your project, open your_app | Gradle Scripts | build.gradle (Module: app) and add the following compile statement to the dependencies{} section to compile the latest version of the SDK −implementation 'com.facebook.android:facebook-login:5.15.3'Step 3 − Add your package name and default activity class name as shown below, click save and continue.Step 4 − Create a Key hash. Based on your operating system you have to copy ... Read More
This example demonstrates how to play videos in Android TextureView 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 − Create an asset folder and copy-paste the video into the asset folder.Step 4 − Add the following code to MainActivity.ktimport android.content.res.AssetFileDescriptor import android.graphics.SurfaceTexture import android.media.MediaPlayer import android.media.MediaPlayer.OnVideoSizeChangedListener import android.os.Build import android.os.Bundle import android.view.Surface import android.view.TextureView import android.view.TextureView.SurfaceTextureListener import androidx.appcompat.app.AppCompatActivity import java.io.IOException class MainActivity : AppCompatActivity(), SurfaceTextureListener, OnVideoSizeChangedListener { private ... Read More
This example demonstrates how to use the TextWatcher class 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 MainActivity.ktimport android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.widget.EditText import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { lateinit var input: EditText lateinit var output: TextView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ... Read More
This example demonstrates how to set the part of the Android text view as clickable 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 MainActivity.ktimport android.os.Bundle import android.text.SpannableString import android.text.Spanned import android.text.method.LinkMovementMethod import android.text.style.ClickableSpan import android.view.View 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) ... Read More
This example demonstrates how to quit an android application programmatically 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 MainActivity.ktimport androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import kotlin.system.exitProcess class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" } fun quitApp(view: View) { ... Read More