Android菜单无法显示

时间:2010-10-25 14:02:48

标签: android menu

我的select_screen_menu.xml

<?xml version="1.0" encoding="utf-8"?>

<menu

  xmlns:android="http://schemas.android.com/apk/res/android">

  <item android:id="@+id/home_menu"
      android:icon="@drawable/home_tab"
      android:title="Home" />
 <item android:id="@+id/submit_report"
      android:icon="@drawable/submit_tab"
      android:title="Submit a Report" />
  <item android:id="@+id/search_list"
      android:icon="@drawable/search_icon"
      android:title="Search the List" />

</menu>

我的活动类将其用作

public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.select_screen_menu, menu);       
  return true;
}

public boolean onOptionsItemSelected(MenuItem item) {  
  switch (item.getItemId()) {
    case R.id.home_menu: {
      Static.backwardTo(User.viewflipper,ConstandsUsed.USER_SELECT_SCREEN);
      return true;
    }
    case R.id.submit_report:
      Static.backwardTo(User.viewflipper, User.sumitAReport_PAGE);
      return true;
    case R.id.search_list:
      Static.backwardTo(User.viewflipper, User.searchTheList_PAGE);
      return true;
    default:
      return super.onOptionsItemSelected(item);      
  }
}

我使用以下代码来识别后退按钮

public boolean onKeyDown(int keyCode, KeyEvent event) {
---
---
}

这两个人没有合作。仅当删除此onkeydown函数时,该菜单才有效。 有没有办法一起使用它 我还需要做其他事吗?

请帮助我,谢谢

2 个答案:

答案 0 :(得分:4)

感谢并为每一个人道歉。我理解我的错误实际上我总是从onkeydown函数返回true。当我改变为返回false如果它不是我需要它的工作的键码

 public boolean onKeyDown(int keyCode, KeyEvent event) {
if(){
------
return true;
}
else
return false;
}

谢谢

答案 1 :(得分:1)

如果我理解正确,您需要在活动中写下来:

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();
}
相关问题