Dynamically Update a ListView on Android using Kotlin

Azhar
Updated on 21-Apr-2020 08:45:12

1K+ Views

This example demonstrates how to dynamically update a ListView on 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 androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.ArrayAdapter import android.widget.Button import android.widget.EditText import android.widget.ListView class MainActivity : AppCompatActivity() {    lateinit var editText: EditText    lateinit var button: Button    lateinit var listView: ListView    var list: ArrayList = ArrayList()    lateinit ... Read More

Check Bluetooth Device Connection with Android Using Kotlin

Azhar
Updated on 21-Apr-2020 08:42:36

2K+ Views

This example demonstrates how to check if a Bluetooth device is connected with an Android device..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.bluetooth.BluetoothDevice import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter import android.os.Bundle import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = ... Read More

Display List View in Android Alert Dialog using Kotlin

Azhar
Updated on 21-Apr-2020 08:39:29

1K+ Views

This example demonstrates how to display a list view in an Android Alert Dialog.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.view.View import android.widget.ArrayAdapter import android.widget.ListView import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    var country = arrayOf(       "India", "Brazil", "Argentina",       "Portugal", "France", "England", "Italy"    )   ... Read More

Rules for the Subscriber Interface in Java 9

raja
Updated on 21-Apr-2020 08:38:18

429 Views

Subscriber interface subscribes to publishers to receive items through onNext() method, error message through the onError() method, or a signal that no more items to be expected through the onComplete() method. Before any of those things happen, the publisher calls onSubscription() method.public interface Subscriber {    public void onSubscribe(Subscription s);    public void onNext(T t);    public void onError(Throwable t);    public void onComplete(); }Rules for Subscriber interface:A Subscriber must call through Subscription.request(long n) method to receive onNext() signals.Subscriber.onComplete() and Subscriber.onError(Throwable t) methods must not call any methods on Subscription or Publisher.Subscriber.onComplete() and Subscriber.onError(Throwable t) methods must consider the Subscription canceled after received ... Read More

Start Service Using AlarmManager in Kotlin for Android

Azhar
Updated on 21-Apr-2020 08:35:44

805 Views

This example demonstrates how to start Service using Alarmmanager in Kotlin Android.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.AlarmManager import android.app.PendingIntent import android.content.Context import android.content.Intent import android.os.Bundle import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import java.util.* class MainActivity : AppCompatActivity() {    private lateinit var btnStart: Button    private lateinit var btnStop: Button    lateinit var pendingIntent: PendingIntent ... Read More

DateTime ToFileTimeUtc Method in C#

AmitDiwan
Updated on 21-Apr-2020 08:02:41

230 Views

The DateTime.ToFileTimeUtc() method in C# is used to convert the value of the current DateTime object to a Windows file time.SyntaxFollowing is the syntax −public long ToFileTimeUtc ();ExampleLet us now see an example to implement the DateTime.ToFileTimeUtc() method −using System; public class Demo {    public static void Main() {       DateTime d = new DateTime(2019, 05, 10, 6, 10, 25);       Console.WriteLine("Date = {0}", d);       long res = d.ToFileTimeUtc();       Console.WriteLine("Windows file time (Utc) = {0}", res);    } }OutputThis will produce the following output −Date = 5/10/2019 6:10:25 AM ... Read More

Create a Process Using ProcessBuilder in Java 9

raja
Updated on 20-Apr-2020 16:24:53

383 Views

Java 9 added ProcessHandle interface to Process API to enhance Process class. An instance of the ProcessHandle interface identifies a local process that allows us to query process status and managing processes, and ProcessHandle.Info allows us to use local code because of the need to obtain the PID of a local process.ProcessBuilder class can be used to create separate operating system processes. In the below example, we can create a process of "notepad" application by using the ProcessBuilder class.Exampleimport java.time.ZoneId; import java.util.stream.Stream; import java.util.stream.Collectors; import java.io.IOException; public class ProcessBuilderTest {    public static void main(String args[]) throws IOException {       ProcessBuilder pb = new ProcessBuilder("notepad.exe"); ... Read More

Pass an Image from One Activity to Another in Kotlin

Azhar
Updated on 20-Apr-2020 13:44:10

2K+ Views

This example demonstrates how to pass an image from one activity to another 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.content.Intent import android.os.Bundle import android.view.View import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"    }    fun ... Read More

Shared Preferences in Kotlin: Save, Edit, Retrieve, and Delete

Azhar
Updated on 20-Apr-2020 13:41:50

646 Views

This example demonstrates how Save, edit, retrieve, delete shared preference data 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 src/MainActivity.ktimport android.content.Context import android.content.SharedPreferences 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 @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") class MainActivity : AppCompatActivity() {    var editTextName: EditText? = ... Read More

Draw Smooth Line Following Finger Using Kotlin

Azhar
Updated on 20-Apr-2020 13:37:42

386 Views

This example demonstrates how to draw a smooth line following my finger using 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.graphics.Bitmap import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint import android.os.Bundle import android.view.MotionEvent import android.view.View import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity(), View.OnTouchListener {    private lateinit var imageView: ImageView    private var bitmap: Bitmap? = null    var ... Read More

Advertisements