Found 417 Articles for Kotlin

Web Scraping in Android Application using Kotlin?

Azhar
Updated on 05-Nov-2020 14:57:03

2K+ Views

This example demonstrates how to perform Web Scraping in 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 android.os.AsyncTask import android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import org.jsoup.Jsoup import java.io.IOException @Suppress("DEPRECATION") class MainActivity : AppCompatActivity() {    private lateinit var textView: TextView    lateinit var button: Button    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState) ... Read More

How to use shared preferences in Android using Kotlin?

Azhar
Updated on 05-Nov-2020 14:55:55

2K+ Views

This example demonstrates how to use shared preferences 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.SharedPreferences import android.os.Bundle import android.preference.PreferenceManager import android.widget.Button import android.widget.CheckBox import android.widget.EditText import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private lateinit var sharedPreferences: SharedPreferences    private lateinit var editor: SharedPreferences.Editor    private lateinit var ... Read More

How to use Calendar Widget using the CalendarView class in Android App using Kotlin?

Azhar
Updated on 05-Nov-2020 14:54:44

891 Views

This example demonstrates how to use Calendar Widget using the CalendarView class in 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.widget.CalendarView import android.widget.CalendarView.OnDateChangeListener import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var calendarView: CalendarView    lateinit var dateView: TextView    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState) ... Read More

How to create custom Alert Dialogs in an Android App using Kotlin?

Azhar
Updated on 05-Nov-2020 14:54:00

1K+ Views

This example demonstrates how to create custom Alert Dialogs 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.app.Dialog import android.content.Context import android.os.Bundle import android.view.View import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private val context: Context = this    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       ... Read More

How to use SearchView in Android Kotlin?

Azhar
Updated on 05-Nov-2020 14:49:17

3K+ Views

This example demonstrates how to use SearchView in Android 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.SearchView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var searchView: SearchView    lateinit var listView: ListView    lateinit var list: ArrayList    lateinit var adapter: ArrayAdapter    override fun onCreate(savedInstanceState: Bundle?) {   ... Read More

How to use XMLPullParser to parse XML in Android using Kotlin?

Azhar
Updated on 05-Nov-2020 14:48:07

876 Views

This example demonstrates how to use XMLPullParser to parse XML 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 − Create a Layout resource file (row.xml) and add the following code −             Step 5 − Create a new asset folder, and inside the asset folder create a Android resource file (model.xml) and add the following code −   ... Read More

How to use JSONObject to parse JSON in Android using Kotlin?

Azhar
Updated on 05-Nov-2020 14:47:22

2K+ Views

This example demonstrates how to use JSONObject to parse JSON 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.TextView import androidx.appcompat.app.AppCompatActivity import org.json.JSONException import org.json.JSONObject class MainActivity : AppCompatActivity() {    private val jsonString = "{\"Employee\":{\"Name\":\"Niyaz\", \"Salary\":56000}}"    lateinit var textView: TextView    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       ... Read More

How to use Location API in Android to track your current location using Kotlin?

Azhar
Updated on 05-Nov-2020 14:46:38

347 Views

This example demonstrates how to use Location API in Android to track your current location 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_maps.xml. Step 3 − Add the following code to src/MapsActivity.ktimport android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.google.android.gms.maps.CameraUpdateFactory import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.OnMapReadyCallback import com.google.android.gms.maps.SupportMapFragment import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.MarkerOptions class MapsActivity : AppCompatActivity(), OnMapReadyCallback {    private lateinit var mMap: GoogleMap    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_maps) ... Read More

How to get the device's IMEI/ESN programmatically in android using Kotlin?

Azhar
Updated on 05-Nov-2020 14:45:54

2K+ Views

This example demonstrates how to get the device's IMEI/ESN 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.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.Manifest import android.content.Context import android.content.pm.PackageManager import android.os.Bundle import android.telephony.TelephonyManager import android.widget.Button import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat class MainActivity : AppCompatActivity() {    lateinit var button: Button    lateinit var textView: TextView    private lateinit ... Read More

How to listen for a WebView finishing loading a URL in Android using Kotlin?

Azhar
Updated on 05-Nov-2020 14:45:09

644 Views

This example demonstrates how to listen for a WebView finishing loading a URL 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.webkit.WebChromeClient import android.webkit.WebView import android.webkit.WebViewClient import android.widget.Button import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var webView: WebView    lateinit var textView: TextView    private lateinit var ... Read More

Advertisements