2014-01-20 4 views
0

я хочу добавить меню в моем классе получает ошибку * Невозможно переопределить окончательный метод из SherlockFragment * пожалуйста скажите мне, как это сделатьдобавление строки меню в SherlockFragmentActivity

моего кода

public class FragementFirst extends SherlockFragment{ 

    Button btn; 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 

       View rootView = inflater.inflate(R.layout.fragementone, container, false); 
       btn = (Button) rootView.findViewById(R.id.butto); 
       setHasOptionsMenu(true); 
       btn.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
      Intent intent = new Intent(getActivity(), FirstActiviry.class); 
       getActivity().startActivity(intent); 

      } 
     }); 
     return rootView; 
    } 
    @Override 
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 
     super.onCreateOptionsMenu(menu, inflater); 
     inflater.inflate(R.menu.first, menu); 
    } 
} 

    <menu xmlns:android="http://schemas.android.com/apk/res/android" > 

<item android:id="@+id/action_task" 
     android:icon="@drawable/icon_xhdpi" 
     android:title="hello" 
     android:showAsAction="ifRoom" /> 
</menu> 

ответ

0

используйте

@Override 
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 
     super.onCreateOptionsMenu(menu, inflater); 
     getSupportMenuInflater().inflate(R.menu.first, menu); 
    } 

вместо

@Override 
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 
     super.onCreateOptionsMenu(menu, inflater); 
     inflater.inflate(R.menu.first, menu); 
    } 

понять учебник есть пожалуйста, посетите http://www.grokkingandroid.com/adding-action-items-from-within-fragments/

Смежные вопросы