onOptionsItemSelected go to a website
-
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.
-
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.
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