当前位置: 代码迷 >> Android >> android MENU开发有关问题
  详细解决方案

android MENU开发有关问题

热度:18   发布时间:2016-05-01 17:29:52.0
android MENU开发问题
strings.xml:


<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="hello">Hello World</string>
  <string name="app_name">Hello World</string>
  <string name="label">您选择为</string>
  <string name="gender">性别</string>
  <string name="male">男</string>
  <string name="female">女</string>
  <string name="hobby">爱好</string>
  <string name="hobby1">游泳</string>
  <string name="hobby2">唱歌</string>
  <string name="hobby3">写JAVA程序</string>
  <string name="ok">确定</string>
</resources>








XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="@+id/EditText01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:editable="false"
android:cursorVisible="false"
android:text="@string/label"
></EditText>
</ScrollView>
</LinearLayout>







代码部分:




package com.msn.cn;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.SubMenu;
import android.widget.EditText;

public class mun extends Activity {
final int MENU_GENDER_MALE=0;  
final int MENU_GENDER_FEMALE=1;
final int MENU_HOBBY1=2;
final int MENU_HOBBY2=3;
final int MENU_HOBBY3=4;
final int MENU_OK=5;
final int MENU_GENDER=6;
final int MENU_HOBBY=7;  
final int GENDER_GROUP=0;  
final int HOBBY_GROUP=1;  
final int MAIN_GROUP=2;
MenuItem[] miaHobby=new MenuItem[3];//爱好菜单组
MenuItem male=null;//男性性别菜单项

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
   
  }
public boolean onCeateOptionsMenu(Menu menu){

SubMenu subMenuGender = menu.addSubMenu(MAIN_GROUP,MENU_GENDER,0,R.string.gender);
subMenuGender.setIcon(R.drawable.gender);
subMenuGender.setHeaderIcon(R.drawable.gender);
male = subMenuGender.add(GENDER_GROUP, MENU_GENDER_MALE, 0, R.string.male);
male.setChecked(true);
subMenuGender.add(GENDER_GROUP, MENU_GENDER_FEMALE, 0, R.string.female);

subMenuGender.setGroupCheckable(GENDER_GROUP, true,true); 
 

SubMenu subMenuHobby = menu.addSubMenu(MAIN_GROUP,MENU_HOBBY,0,R.string.hobby);
subMenuHobby.setIcon(R.drawable.hobby); 
miaHobby[0]=subMenuHobby.add(HOBBY_GROUP, MENU_HOBBY1, 0, R.string.hobby1);
miaHobby[1]=subMenuHobby.add(HOBBY_GROUP, MENU_HOBBY2, 0, R.string.hobby2);
miaHobby[2]=subMenuHobby.add(HOBBY_GROUP, MENU_HOBBY3, 0, R.string.hobby3);
  相关解决方案