Basic Andriod Menu Code help to open URL link

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Basic Andriod Menu Code help to open URL link

Postby lucy » Sat Aug 28, 2010 8:58 pm

Hi,
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;
}

}
lucy
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Aug 20, 2010 2:59 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests