Android Articles

Page 21 of 125

How can we get the current language selected in the Android device using Kotlin?

Azhar
Azhar
Updated on 18-Aug-2020 1K+ Views

This example demonstrates how to get the current language selected in the Android device 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 import java.util.* class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val textView: ...

Read More

How to use the recyclerview with a database in Android using Kotlin?

Azhar
Azhar
Updated on 18-Aug-2020 2K+ Views

This example demonstrates how to use the recyclerview with a database 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.os.Bundle import android.text.TextUtils import android.view.LayoutInflater import android.view.View import android.widget.Button import android.widget.EditText import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView class MainActivity : AppCompatActivity() {    private lateinit var dataBase: SqliteDatabase    override fun onCreate(savedInstanceState: Bundle?) { ...

Read More

How to run a method every 10 seconds in Android using Kotlin?

Azhar
Azhar
Updated on 18-Aug-2020 4K+ Views

This example demonstrates how to run a method every 10 seconds 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.os.Bundle import android.os.Handler import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    var handler: Handler = Handler()    var runnable: Runnable? = null    var delay = 10000    override fun onCreate(savedInstanceState: Bundle?) {       ...

Read More

How to handle the click event in Listview in Android using Kotlin?

Azhar
Azhar
Updated on 18-Aug-2020 3K+ Views

This example demonstrates how to handle the click event in Listview 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.os.Bundle import android.widget.ArrayAdapter import android.widget.ListView import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import kotlin.collections.ArrayList class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"     ...

Read More

How to play YouTube videos in my Android application using Kotlin?

Azhar
Azhar
Updated on 18-Aug-2020 1K+ Views

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 More

How to detect swipe direction between left/right and up/down in Android using Kotlin?

Azhar
Azhar
Updated on 18-Aug-2020 968 Views

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 More

How to display progress dialog before starting an activity in Android using Kotlin?

Azhar
Azhar
Updated on 18-Aug-2020 460 Views

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 More

How to detect Scroll Up & Scroll down in Android ListView using Kotlin?

Azhar
Azhar
Updated on 18-Aug-2020 1K+ Views

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 More

How to copy text programmatically (Ctrl+C) in my Android app using Kotlin?

Azhar
Azhar
Updated on 21-Jul-2020 539 Views

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 More

How do I programmatically add buttons into layout one by one in several lines using Kotlin?

Azhar
Azhar
Updated on 21-Jul-2020 741 Views

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 More
Showing 201–210 of 1,250 articles
« Prev 1 19 20 21 22 23 125 Next »
Advertisements