Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. onOptionsItemSelected go to a website

onOptionsItemSelected go to a website

Scheduled Pinned Locked Moved Android
androidquestionhelpcsharp
2 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    The_Arcaniac
    wrote on last edited by
    #1

    Hello, and thank you for you patience with me. I am knew to Android, however I have been programming LAMP and Visual Basic and C# for many years. I am using Android Studio 3.5 and using Kotlin as the language. I have a very simple question for many of you, however, it is vexing me. I would greatly appreciate your help. I have created a menu in my android app. The problem I am having is, how do I select a Menu Item and go to a web page? Here is the code I have. From MainActivity.kt-----------------------------------------

    override fun onOptionsItemSelected(item: MenuItem): Boolean {

        return when (item.itemId) {
            R.id.action\_locate -> true
            else -> super.onOptionsItemSelected(item)
        }
        return when (item.itemId) {
            R.id.action\_scanner -> true
            else -> super.onOptionsItemSelected(item)
        }
        return when (item.itemId) {
            R.id.action\_qrcodescanner -> true
            else -> super.onOptionsItemSelected(item)
        }
        return when (item.itemId) {
            R.id.action\_mainsite -> true
            else -> super.onOptionsItemSelected(item)
        }
    

    ------------------------------------------------------------ MenuMain.xml-------------------------------------------------

    --------------------------------------------- Please tell me if you need any other code. I just want to know how to make a menu item go to a webpage. Thank you.

    D 1 Reply Last reply
    0
    • T The_Arcaniac

      Hello, and thank you for you patience with me. I am knew to Android, however I have been programming LAMP and Visual Basic and C# for many years. I am using Android Studio 3.5 and using Kotlin as the language. I have a very simple question for many of you, however, it is vexing me. I would greatly appreciate your help. I have created a menu in my android app. The problem I am having is, how do I select a Menu Item and go to a web page? Here is the code I have. From MainActivity.kt-----------------------------------------

      override fun onOptionsItemSelected(item: MenuItem): Boolean {

          return when (item.itemId) {
              R.id.action\_locate -> true
              else -> super.onOptionsItemSelected(item)
          }
          return when (item.itemId) {
              R.id.action\_scanner -> true
              else -> super.onOptionsItemSelected(item)
          }
          return when (item.itemId) {
              R.id.action\_qrcodescanner -> true
              else -> super.onOptionsItemSelected(item)
          }
          return when (item.itemId) {
              R.id.action\_mainsite -> true
              else -> super.onOptionsItemSelected(item)
          }
      

      ------------------------------------------------------------ MenuMain.xml-------------------------------------------------

      --------------------------------------------- Please tell me if you need any other code. I just want to know how to make a menu item go to a webpage. Thank you.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      In response to that menu item, could you do something like:

      startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "https://www.google.com")));

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups