Could anyone help me with some basic android code, i have followed a tutorial to display a menu once the menu button on the phone is pressed.
I just dont know how to add an action to the menu button to do something, i would like them to open a url link in the phone browser.
Hope some one can help
menu.xml code below
- Code: Select all
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/text1"
android:title="Text" />
<item android:id="@+id/text2"
android:title="Text" />
<item android:id="@+id/text3"
android:title="Text" />
</menu>
Java code below
- Code: Select all
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.text1: Toast.makeText(this, "You pressed
the icon!", Toast.LENGTH_LONG).show();
break;
case R.id.text2: Toast.makeText(this, "You pressed
the icon!", Toast.LENGTH_LONG).show();
break;
case R.id.text3: Toast.makeText(this, "You pressed
the icon!", Toast.LENGTH_LONG).show();
break;
}
return true;
}
}

