我目前正在嘗試在我的應用程序中創建基本操作欄。我試圖重寫我的主要活動中的onCreateOptionsMenu方法,但得到一個錯誤,「方法不會覆蓋或實現超類型的方法」。但是,我在'Activity'類定義(https://developer.android.com/reference/android/app/Activity.html)中看到它確實包含該方法。所以,請幫我理解爲什麼我無法覆蓋該方法?覆蓋OnCreateOptionsMenu方法
這裏的MainActivity類別代碼,所有的進口沿:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean OnCreateOptionsMenu(Menu menu)
{
//Inflate the menu. this adds items to the action bar if it is present
getMenuInflater().inflate(R.menu.menu_main,menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case R.id.action_create_order:
//Code to run when the create order item is clicked
Intent intent=new Intent(this,OrderActivity.class);
startActivity(intent);
return true;
case R.id.action_settings:
//Code to run when the settings item is clicked
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
嘗試將'OnCreateOptionsMenu'更改爲'onCreateOptionsMenu'。用'o'替換'O'(小寫字母)(小寫) – SripadRaj
oops :) ...非常感謝:) – Guru316