Android Create Menu Instance _android

Source: Internet
Author: User

The example in this article describes how Android creates the menu menu. Share to everyone for your reference. The specific methods are as follows:

Copy Code code as follows:
Package com.test;

Import android.app.Activity;

Import android.content.Intent;
Import Android.os.Bundle;
Import android.provider.Settings;
Import Android.view.Menu;
Import Android.view.MenuInflater;
Import Android.view.MenuItem;

public class Testandroidactivity extends activity {
@Override
public boolean Oncreateoptionsmenu (Menu menu) {
TODO auto-generated Method Stub
Super.oncreateoptionsmenu (menu);
Menuinflater inflater = Getmenuinflater ();
Inflater.inflate (R.menu.menu, menu);
return true;
}

/** called the activity is a. */
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
}

@Override
public boolean onoptionsitemselected (MenuItem item) {
TODO auto-generated Method Stub
Switch (Item.getitemid ())
{
Case R.id.settings:
StartActivity (New Intent (This,com.test.settings.class));
return true;
}
return false;
}
}

Copy Code code as follows:
Package com.test;

Import Android.os.Bundle;
Import android.preference.PreferenceActivity;

public class Settings extends Preferenceactivity {

@Override
protected void OnCreate (Bundle savedinstancestate) {
TODO auto-generated Method Stub
Super.oncreate (savedinstancestate);
Addpreferencesfromresource (r.xml.settings);
}
}

The related configuration files are as follows:

Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<preferencescreen xmlns:android= "Http://schemas.android.com/apk/res/android" >
<checkboxpreference android:key= "Music" android:summary= "@string/music_summary" android:defaultvalue= "true" android:title= "@string/music_title"/>
<checkboxpreference android:key= "Hints" android:summary= "@string/hints_summary" android:title= "@string/hints_ Title "/>
</PreferenceScreen>

I hope this article will help you with your Android program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.