Found 2041 Articles for Mobile Development

How to get the selected index of a RadioGroup in Android using Kotlin?

Azhar
Updated on 23-May-2020 12:07:21

2K+ Views

This example demonstrates how to get the selected index of a RadioGroup in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ? New Project and fill allrequired 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.Bundle import android.widget.Button import android.widget.RadioButton import android.widget.RadioGroup import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private lateinit var textView: TextView    private lateinit var button: Button ... Read More

How to create a Expandable listView using Kotlin?

Azhar
Updated on 23-May-2020 12:00:28

3K+ Views

This example demonstrates how to create a Expandable 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.Example     Step 3 − Create a new kotlin class CustomExpandableListAdapter.kt and add the following code −Exampleimport android.content.Context import android.graphics.Typeface import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.BaseExpandableListAdapter import android.widget.TextView import java.util.HashMap class CustomExpandableListAdapter internal constructor(    private val context: Context,    private val titleList: List,    private val dataList: HashMap    ) : BaseExpandableListAdapter() {   ... Read More

How to detect shake events in Kotlin?

Azhar
Updated on 23-May-2020 11:49:15

1K+ Views

This example demonstrates how to detect shake events 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.hardware.Sensor import android.hardware.SensorEvent import android.hardware.SensorEventListener import android.hardware.SensorManager import android.os.Bundle import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import java.util.* import kotlin.math.sqrt class MainActivity : AppCompatActivity() {    private var sensorManager: SensorManager? = null    private var acceleration = 0f    private var currentAcceleration = 0f ... Read More

Barcode Scanning in Android using Kotlin?

Azhar
Updated on 23-May-2020 11:43:24

2K+ Views

This example demonstrates how to implement bar code scanning 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 the dependency to build.gradle (Module:app)implementation 'com.google.zxing:core:3.3.3' implementation 'com.journeyapps:zxing-android-embedded:3.2.0@aar'Step 4 − Add the following code to src/MainActivity.ktExampleimport android.content.Intent import android.os.Bundle import android.util.Log import android.widget.Button import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.google.zxing.integration.android.IntentIntegrator class MainActivity : AppCompatActivity() {    lateinit var btnBarcode: Button    lateinit var textView: ... Read More

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

Azhar
Updated on 23-May-2020 11:37:22

274 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
Updated on 23-May-2020 11:27:11

630 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 make an Android SlidingDrawer slide out from the left in Kotlin?

Azhar
Updated on 23-May-2020 11:15:34

105 Views

ample demonstrates how to make an Android SlidingDrawer slide out from the left 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 androidx.appcompat.app.AppCompatActivity import android.os.Bundle class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"    } }Step 4 ... Read More

How to get a list of installed Android applications in Kotlin?

Azhar
Updated on 23-May-2020 11:08:59

1K+ Views

This example demonstrates how to get a list of installed Android applications 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.pm.ApplicationInfo import android.os.Bundle import android.util.Log import android.widget.ArrayAdapter import android.widget.ListView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var listView: ListView    var arrayAdapter: ArrayAdapter? = null    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main) ... Read More

How to make an ImageView with rounded corners on Android App using Kotlin?

Azhar
Updated on 23-May-2020 11:04:20

900 Views

This example demonstrates how to make an ImageView with rounded corners on 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.ktExampleimport android.graphics.* import android.graphics.drawable.BitmapDrawable import android.os.Bundle import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val imageView ... Read More

How to enable or disable the GPS programmatically on Kotlin?

Azhar
Updated on 23-May-2020 10:59:06

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

Advertisements