这是我的名为Home1
public class Home1 extends SherlockFragment
{
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.dashboard, container, false);
setHasOptionsMenu(true);
myevents = new ArrayList<Myevent>();
myevents_searchable = new ArrayList<Myevent>();
listview = (ListView) rootView.findViewById(R.id.events);
Button btn=(Button)rootView.findViewById(R.id.create_new_tkt);
btn.setVisibility(View.GONE);
loginaync = new LoginAsync();
loginaync.execute((Void) null);
listview.setOnItemClickListener(listener);
return rootView;
}
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (loading != null)
{
if(loading.isShowing())
{
loading.dismiss();
}
}
}
public void onCreateOptionMenu(Menu menu, MenuInflater inflater)
{
super.onCreateOptionsMenu(menu, inflater);
Log.e("hii_onoptionmenu","Test");
inflater.inflate(R.menu.main, menu);
MenuItem menuitem = menu.findItem(R.id.action_refresh);
menuitem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// TODO Auto-generated method stub
loginaync = null;
loginaync = new LoginAsync();
loginaync.execute((Void) null);
return true;
}
});
}
在这里,正如您所看到的,我已经扩展了SherlockFragment
,我也尝试实现菜单。但是没有调用onCreateOptionMenu()
方法。这边有什么问题?为什么不调用此方法?请帮助。
答案 0 :(得分:0)
请检查您是否覆盖
@Override
public void onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu, com.actionbarsherlock.view.MenuInflater inflater) {
}
AND NOT
@Override
public final void onCreateOptionsMenu(android.view.Menu menu, android.view.MenuInflater inflater) {
}
参数类型不同(来自不同的包)。
答案 1 :(得分:0)
我找到了解决方案。
public class Home1 extends SherlockFragment implements OnCreateOptionsMenuListener
{
}
我在班上实现了OnCreateOptionsMenuListener。它会覆盖该方法。一旦覆盖了方法,就可以删除OnCreateOptionsMenuListener的实现。谢谢你的建议。