我正在嘗試創建菜單演示,但無法看到菜單。我只能看到佈局中的「TextView」視圖。下面是代碼:在(RES \菜單)在Android中看不到選項菜單
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:title="@string/new_game"
android:id="@+id/new_game">
</item>
<item
android:title="@string/quit"
android:id="@+id/quit"
>
</item>
</group>
</menu>
demomenu.java
menu.xml文件
package com.test.demomenu;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
public class demomenu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
//super.onCreateOptionsMenu(menu);
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.game_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
Toast.makeText(this, "This is the item", Toast.LENGTH_LONG).show();
return true;
}
}
main.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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
的strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, demomenu!</string>
<string name="app_name">Demo Menu</string>
<string name="new_game">New Game</string>
<string name="quit">Quit</string>
</resources>
當我運行該項目時,我只能看到「TextView」而不是菜單。如果有人能告訴我這個應用程序出了什麼問題,我將不勝感激。
感謝, 希德
我沒有從菜單中刪除組標籤,但仍然是同樣的問題,我該如何調試應用程序。 – Sid 2011-02-14 00:12:37