|
Android example source code file (MenuInflateFromXml.java)
The MenuInflateFromXml.java Android example source code/* * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.android.apis.app; import com.example.android.apis.R; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; /** * Demonstrates inflating menus from XML. There are different menu XML resources * that the user can choose to inflate. First, select an example resource from * the spinner, and then hit the menu button. To choose another, back out of the * activity and start over. */ public class MenuInflateFromXml extends Activity { /** * Different example menu resources. */ private static final int sMenuExampleResources[] = { R.menu.title_only, R.menu.title_icon, R.menu.submenu, R.menu.groups, R.menu.checkable, R.menu.shortcuts, R.menu.order, R.menu.category_order, R.menu.visible, R.menu.disabled }; /** * Names corresponding to the different example menu resources. */ private static final String sMenuExampleNames[] = { "Title only", "Title and Icon", "Submenu", "Groups", "Checkable", "Shortcuts", "Order", "Category and Order", "Visible", "Disabled" }; /** * Lets the user choose a menu resource. */ private Spinner mSpinner; /** * Shown as instructions. */ private TextView mInstructionsText; /** * Safe to hold on to this. */ private Menu mMenu; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create a simple layout LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); // Create the spinner to allow the user to choose a menu XML ArrayAdapter<String> adapter = new ArrayAdapter Other Android examples (source code examples)Here is a short list of links related to this Android MenuInflateFromXml.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.