- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 417 Articles for Kotlin
![Soumak De](https://www.tutorialspoint.com/assets/profiles/390759/profile/60_3898744-1646125996.png)
869 Views
Exception is an important aspect of any programming language. It prevents our code from generating incorrect output at runtime.The concept of exception in Kotlin is very much same as it is in Java. All the exceptions in Kotlin are the descendants of Throwable class. In Kotlin, developers do have the privilege to create their own custom Exception.Custom Exceptions are a part of unchecked exceptions which means they will be thrown at the runtime.Before getting into custom exceptions in Kotlin, let's take a look checked and unchecked exceptions.Checked ExceptionsChecked exceptions are those which are checked at the compile time. In the ... Read More
![Soumak De](https://www.tutorialspoint.com/assets/profiles/390759/profile/60_3898744-1646125996.png)
2K+ Views
A Map is a collection where data is stored as a key-value pair and the corresponding key has to be unique. A HashMap is a collection class based upon MutableMap interface and it does that by implementing MutableMap interface of HashTable. Kotlin provides four types of constructor to define and manipulate HashMap.HashMap() – It is the default constructor which helps us create an empty HashMap.HashMap(initialCapacity: Int, loadFactor: Float = 0f) – It helps us create a HashMap using initial capacity; if it is not provided, then it will be ignored and it will act as default HashMap().HashMap(initialCapacity: Int) – It ... Read More
![Azhar](https://www.tutorialspoint.com/assets/profiles/124637/profile/60_166181-1565938637.jpg)
2K+ Views
This example demonstrates how to change a TextView's style at runtime 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 in res/values/styles.xml bold|italic #FFFFFF normal #C0C0C0 Step 4 − Add the following code in res/values/colors.xml @android:color/holo_green_light @android:color/holo_red_dark Step ... Read More
![Azhar](https://www.tutorialspoint.com/assets/profiles/124637/profile/60_166181-1565938637.jpg)
2K+ Views
This example demonstrates how to send a notification from a service 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.Intent import android.os.Bundle import android.view.View import android.widget.EditText import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat class MainActivity : AppCompatActivity() { lateinit var editText: EditText override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) ... Read More
![Azhar](https://www.tutorialspoint.com/assets/profiles/124637/profile/60_166181-1565938637.jpg)
615 Views
This example demonstrates how to use glide to download an image into a bitmap using KotlinStep 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.graphics.Bitmap import android.graphics.drawable.Drawable import android.os.Bundle import android.widget.ImageView import androidx.annotation.Nullable import androidx.appcompat.app.AppCompatActivity import com.bumptech.glide.Glide import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition; class MainActivity : AppCompatActivity() { lateinit var imageView: ImageView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ... Read More
![Azhar](https://www.tutorialspoint.com/assets/profiles/124637/profile/60_166181-1565938637.jpg)
258 Views
This example demonstrates how to disable GridView scrolling 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.MotionEvent import android.view.View import android.view.ViewGroup import android.widget.* import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { private lateinit var gridView: GridView var imageIDs = arrayOf( R.drawable.ronaldo, R.drawable.andre, ... Read More
![Azhar](https://www.tutorialspoint.com/assets/profiles/124637/profile/60_166181-1565938637.jpg)
433 Views
This example demonstrates how to use the Android Picasso library to download images 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 to the build gradle (Module: app)implementation 'com.squareup.picasso:picasso:2.4.0'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.Button import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity import com.squareup.picasso.Picasso class MainActivity : AppCompatActivity() { lateinit var imageView: ImageView lateinit var btnDownload: Button override fun onCreate(savedInstanceState: ... Read More
![Azhar](https://www.tutorialspoint.com/assets/profiles/124637/profile/60_166181-1565938637.jpg)
3K+ Views
This example demonstrates how to create a swipe refresh layout 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 androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.os.Handler import android.widget.TextView import androidx.swiperefreshlayout.widget.SwipeRefreshLayout class MainActivity : AppCompatActivity() { lateinit var swipeRefreshLayout: SwipeRefreshLayout lateinit var textView: TextView var number: Int = 0 override fun onCreate(savedInstanceState: Bundle?) { ... Read More
![Azhar](https://www.tutorialspoint.com/assets/profiles/124637/profile/60_166181-1565938637.jpg)
790 Views
This example demonstrates how to close all Android activities at once 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.ktpackage com.example.q28 import android.content.Intent import android.os.Bundle import android.widget.Button import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { lateinit var button: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) title = ... Read More
![Azhar](https://www.tutorialspoint.com/assets/profiles/124637/profile/60_166181-1565938637.jpg)
260 Views
This example demonstrates how to get the Android Emulator's IP address 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.net.wifi.WifiManager import android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import android.text.format.Formatter class MainActivity : AppCompatActivity() { lateinit var button: Button lateinit var textView: TextView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ... Read More