위로 가기 여러 탭이있는 상단에 탐색 표시 줄이있는 Android 앱과 그 부분이 잘 작동하지만 이제 메뉴를 동적으로 추가 할 수 있기를 원합니다. 다른 단편에서 액션 바에 아이템을 가져옵니다 (일부 단편은 다른 옵션을 사용할 수 있기 때문에). 지금까지 내가 무엇을 시도했는지에 관계없이 onCreateOptionsMenu를 호출 할 수없는 것처럼 보입니다. 여기에 내가 가진 무엇 지금까지SherlockActionBar에서 메뉴 항목을 동적으로 추가하기 단편 탭
//First I have a holder class that is used to navigate between the different Fragment Tabs
public class ActionHolder extends SherlockFragmentActivity implements ActionBar.TabListener {....
//And then I have this method for switching Fragments based on what Tab is selected
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
int selectedTab = tab.getPosition();
if (selectedTab == 0) {
SalesMainScreen salesScreen = new SalesMainScreen();
ft.replace(R.id.content, salesScreen);
}
else if (selectedTab == 1) {
ClientMainScreen clientScreen = new ClientMainScreen();
ft.replace(R.id.content, clientScreen);
}.....
지금 여기에 내가
@Override
public void onCreate (Bundle savedInstanceState) {
Log.i("message","the oncreate method was called");
setHasOptionsMenu(true);
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved) {
return inflater.inflate(R.layout.salesmainscreen, group, false);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Log.i("message", "the oncreatemenu method called");
inflater.inflate(R.menu.menu_refresh, menu);
super.onCreateOptionsMenu(menu, inflater);
}
내가 한 OnCreate를 볼 항목은 작업 표시 줄에 추가 된 몇 가지 메뉴가 할 탭의 조각합니다 (SalesMainScreen) 중 하나입니다 로그 메시지가 호출되었지만 onCreateOptionsMenu 로그가 전혀 호출되지 않습니다. 또한 때로는 가져 오기로 인해 문제가 발생한다는 것을 알고 있습니다. 그러나 Sherlock Menu 및 Menu Inflater를 가져 오면 OnCreateOptionMenu 메서드에서 호환되지 않는 모든 종류의 오류 메시지가 나타납니다. 이 설정에서 메뉴 항목을 작업 표시 줄에 동적으로 추가 할 수 있습니까? 아니면 항목을 추가 한 다음 표시되는 단편에 적용되지 않는 항목에 대해 조치를 취하지 않아야합니까?
은 super.onCreate (savedInstanceState)와 함께 있어야 할 수도 있습니다. setHasOptionsMenu (true)를 수행합니다. ? 그것은 모든 것을 덮어 씌울 것인가? – RdPC