Azhar

Azhar

451 Articles Published

Articles by Azhar

Page 29 of 46

How to automatically start and stop an Async task in Kotlin?

Azhar
Azhar
Updated on 23-May-2020 409 Views

This example demonstrates how to automatically start and stop an Async task 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.Example         Step 3 − Add the following code to src/MainActivity.ktExampleimport android.os.AsyncTask import android.os.Bundle import android.view.View import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import kotlinx.android.synthetic.main.activity_main.* import java.lang.ref.WeakReference class MainActivity : AppCompatActivity() {    var variable = 10    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)     ...

Read More

How to stop asynctask thread in Kotlin?

Azhar
Azhar
Updated on 23-May-2020 828 Views

This example demonstrates how to stop an asynctask thread 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.Example             Step 3 − Add the following code to src/MainActivity.ktExampleimport android.graphics.Color import android.os.AsyncTask import android.os.Bundle import android.view.View import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.util.* class MainActivity : AppCompatActivity() {    private lateinit var btnDo: Button    private lateinit var btnCancel: Button    private lateinit var textView: TextView    private ...

Read More

How to enable or disable the GPS programmatically on Kotlin?

Azhar
Azhar
Updated on 23-May-2020 2K+ Views

This example demonstrates how to enable or disable the GPS programmatically on 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 &minsu; Add the following code to res/layout/activity_main.xml.Example             Step 3 − Add the following code to src/MainActivity.ktimport android.content.Context import android.content.Intent import android.location.LocationManager import android.os.Bundle import android.provider.Settings import android.view.View import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private lateinit var context: Context    var intent1: Intent? = null    lateinit var textView: TextView   ...

Read More

How to create a listView with a checkBox in Kotlin?

Azhar
Azhar
Updated on 23-May-2020 1K+ Views

This example demonstrates how to Create a listView with a checkBox 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.Example Step 3 − Add the following code to src/MainActivity.ktExampleimport android.view.View import android.widget.AdapterView.OnItemClickListener import android.widget.ListView import androidx.appcompat.app.AppCompatActivity import java.util.* class MainActivity : AppCompatActivity() {    private var dataModel: ArrayList? = null    private lateinit var listView: ListView    private lateinit var adapter: CustomAdapter    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState) ...

Read More

How to create a WebView in an Android App using Kotlin?

Azhar
Azhar
Updated on 23-May-2020 2K+ Views

This example demonstrates how to create a WebView 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.Example         Step 3 − Add the following code to src/MainActivity.ktExampleimport android.os.Bundle import android.webkit.WebView import android.webkit.WebViewClient import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private val webView: WebView? = null    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val webView = findViewById(R.id.webView)       ...

Read More

Add and Remove Views in Android Dynamically in Kotlin?

Azhar
Azhar
Updated on 23-May-2020 4K+ Views

This example demonstrates how to Add and Remove Views in Android Dynamically 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.Example                           Step 3 − Add the following code to src/MainActivity.ktExampleimport android.content.Context import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.widget.LinearLayout import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private var parentLinearLayout: LinearLayout? = null   ...

Read More

How to use ArrayAdapter in android to create a simple listview in Kotlin?

Azhar
Azhar
Updated on 21-Apr-2020 5K+ Views

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

How to use SearchView in the Toolbar in Kotlin?

Azhar
Azhar
Updated on 21-Apr-2020 3K+ Views

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

How to get Spinner value in Kotlin?

Azhar
Azhar
Updated on 21-Apr-2020 4K+ Views

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

How to programmatically turn off and turn on WiFi in Kotlin?

Azhar
Azhar
Updated on 21-Apr-2020 1K+ Views

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
Showing 281–290 of 451 articles
« Prev 1 27 28 29 30 31 46 Next »
Advertisements