如何链接菜单到Android中的新页面

时间:2015-03-17 00:55:31

标签: android

这是我的代码,但它崩溃了:

public boolean onCreateOptionsMenu(Menu menu) {

    SubMenu sub = menu.addSubMenu(0, 1, 1, "register");
    sub.add(0, 3, 1, "register book");
    sub.add(0, 4, 2, "register new book");
    menu.add(0, 2, 2, "report");
    return super.onCreateOptionsMenu(menu);

}

public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()){

        case 4:
                Intent intent = new Intent(bookActivity.this, newbookActivity.class);
                bookActivity.this.startActivity(intent);
                break;

        return super.onOptionsItemSelected(item);
    }
}

0 个答案:

没有答案