Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Kotlin Articles
Page 15 of 21
How to play YouTube videos in my Android application using Kotlin?
This example demonstrates how to play YouTube videos in my Android application 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 androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import java.util.* class MainActivity : AppCompatActivity() { private lateinit var recyclerView:RecyclerView private var youtubeVideos = Vector() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) ...
Read MoreHow to detect swipe direction between left/right and up/down in Android using Kotlin?
This example demonstrates how to detect swipe direction between left/right and up/down in 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.os.Bundle import android.view.GestureDetector import android.view.MotionEvent import android.view.View import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import kotlin.math.abs class MainActivity : AppCompatActivity() { var onSwipeTouchListener: OnSwipeTouchListener? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ...
Read MoreHow to display progress dialog before starting an activity in Android using Kotlin?
This example demonstrates how to display progress dialog before starting an activity in 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.app.ProgressDialog import android.os.AsyncTask import android.os.Bundle import androidx.appcompat.app.AppCompatActivity @Suppress("DEPRECATION") class MainActivity : AppCompatActivity() { private lateinit var progressDialog: ProgressDialog override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title ...
Read MoreHow to detect Scroll Up & Scroll down in Android ListView using Kotlin?
This example demonstrates how to detect Scroll Up & Scroll down in Android ListView 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.* import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { private var scrollView: ScrollView? = null private lateinit var listView: ListView private var numbers = arrayOf( "1", "2", ...
Read MoreHow to copy text programmatically (Ctrl+C) in my Android app using Kotlin?
This example demonstrates how to copy text programmatically (Ctrl+C) in my 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.content.ClipData import android.content.ClipboardManager import android.content.Context import android.os.Bundle import android.view.View import android.widget.EditText import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { lateinit var editText: EditText lateinit var textView: TextView lateinit var clipboardManager: ClipboardManager ...
Read MoreHow do I programmatically add buttons into layout one by one in several lines using Kotlin?
This example demonstrates how to programmatically add buttons into layout one by one in several lines 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.view.Gravity import android.widget.Button import android.widget.LinearLayout import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" val layout = LinearLayout(this) ...
Read MoreHow to get and store device ID in Android using Kotlin?
This example demonstrates how to get and store device ID in 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.provider.Settings import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" val textView: TextView = findViewById(R.id.textView) ...
Read MoreHow to update listview after insert values in Android sqlite using Kotlin?
This example demonstrates how to update listview after insert values in Android sqlite 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.* import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { private lateinit var save: Button private lateinit var refresh: Button private lateinit var name: EditText private lateinit var salary: EditText ...
Read MoreHow to prevent a dialog from closing when a button is clicked using Kotlin?
This example demonstrates how to prevent a dialog from closing when a button is clicked 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.Example Step 3 − Add the following code to src/MainActivity.ktimport androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AlertDialog class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = "KotlinApp" val dialog: ...
Read MoreHow to turn on flashlight programmatically in Android using Kotlin?
This example demonstrates how to turn on flashlight programmatically in 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.xmlExample Step 3 − Add the following code to src/MainActivity.ktimport android.content.Context import android.content.DialogInterface import android.content.pm.PackageManager import android.hardware.camera2.CameraAccessException import android.hardware.camera2.CameraManager import android.os.Build import android.os.Bundle import android.widget.ToggleButton import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { private lateinit var cameraManager: CameraManager private lateinit var cameraId: String private lateinit var toggleButton: ToggleButton ...
Read More