Functions

A code block consisting of multiple lines of code that perform an action.

Click button to open URL

- Posted in Functions by

Click a button to open URL.

1
2
3
4
5
6
7
8
hBottom.kStreetViewLink.setOnClickListener { 

    val hStreetURL = "YOUR-URL-HERE"
    val openURL = Intent(Intent.ACTION_VIEW) 
    openURL.data = Uri.parse(hStreetURL) 
    startActivity(openURL) 

  }

Where:

1️⃣   Specify the element to monitor, and use the .setOnClickListener event to check if the user clicks the element specified.

3️⃣   Provide the target URL here.


Expected outcome:

  1. Launch the user's default browser.
  2. Go to the target URL using the default browser.