這些都是錯誤的:爲什麼我會收到這些錯誤?
The method getMenuInflater() is undefined for the type HomeFragment
-Line 27
The method onCreateOptionsMenu(Menu) of type HomeFragment must override or implement a supertype method
-Line 29
The method onCreateOptionsMenu(Menu) of type HomeFragment must override or implement a supertype method
-Line 25
所有這些都是在我的HomeFragment.java
package com.colourity.snatsh;
import com.colourity.snatsh.R;
import java.util.ArrayList;
import com.colourity.snatsh.adapter.NavDrawerListAdapter;
import com.colourity.snatsh.model.NavDrawerItem;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
public class HomeFragment extends Fragment {
public HomeFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
return rootView;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
}
這當我嘗試在0123上使用動作欄圖標時發生,而不是MainActivity
。我是新的,所以對我來說很簡單。任何幫助都會很棒。而且解決方案會很好。
編輯
我更新的代碼:
package com.colourity.snatsh;
import com.colourity.snatsh.R;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
public class HomeFragment extends Fragment {
public HomeFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
return rootView;
}
@Override
public void onCreateOptionsMenu (Menu menu, MenuInflater inflater) {
// Inflate the menu items for use in the action bar
MenuInflater inflater1 = getMenuInflater();
inflater1.inflate(R.menu.main, menu);
return;
}
private MenuInflater getMenuInflater() {
// TODO Auto-generated method stub
return null;
}
}
...現在,顯示您的更新代碼。 –
不確定它是否正確,但正在更新。 @ shree202 – user3342131
如果您嘗試在您的活動中添加ActionBar,請參閱本教程:http://developer.android.com/guide/topics/ui/actionbar.html –