2013-01-04 1 views
0
  1. я использую actionsherlockbar Library + JfenisteinSlidingMenu

вопрос: как добавить динамически optionmenu находится в ActionBar в каждом фрагментекак добавить параметрMenu в каждый фрагмент. (Android + actionsherlock + jfensteinSlidingMenu

я попытался ниже, но optionmenu такое же? на каждой странице .. как я могу это сделать?

public class FragmentChangeActivity extends BaseActivity { 

private Fragment mContent; 
private String json = null; 

public FragmentChangeActivity() { 
    super(R.string.changing_fragments); 
} 

@SuppressWarnings("unused") 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    // set the Above View 
    if (savedInstanceState != null) 
     mContent = getSupportFragmentManager().getFragment(savedInstanceState, "mContent"); 
    if (mContent == null) 
     mContent = new ColorFragment(android.R.color.white);  




    // set the Above View 
    setContentView(R.layout.content_frame); 
    getSupportFragmentManager() 
    .beginTransaction() 
    .replace(R.id.content_frame, mContent) 
    .commit(); 

    // set the Behind View 
    ColorMenuFragment colorMenuFragment = new ColorMenuFragment(); 
    LeftMenuFragment leftMenu = new LeftMenuFragment(); 
    setBehindContentView(R.layout.menu_frame); 
    getSupportFragmentManager() 
    .beginTransaction() 
    .replace(R.id.menu_frame, colorMenuFragment) 
    .commit(); 

    // customize the SlidingMenu 
    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); 
} 

@Override 
public void onSaveInstanceState(Bundle outState) { 
    super.onSaveInstanceState(outState); 
    getSupportFragmentManager().putFragment(outState, "mContent", mContent); 
} 

public void switchContent(Fragment fragment) { 
    mContent = fragment; 
    getSupportFragmentManager() 
    .beginTransaction() 
    .replace(R.id.content_frame, fragment) 
    .commit(); 
    getSlidingMenu().showAbove(); 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
    case android.R.id.home: 
     toggle(); 
     return true; 
    case R.id.github: 
     Utils.goToGitHub(this); 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getSupportMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

} 

ответ

0

Вы не добавляйте меню опций в Fragme nts, ​​но в Fragment Activity и Fragment Activity будут действовать как контейнер, содержащий фрагменты.

0

В вашем каждом меню раздувания раздувания тоже? Я не знаю о lib, но надеюсь, что это может вам помочь это хорошо работает для меня. просто возвращает ложь в вашем onOptionsItemSelected см Этот пример

в моей деятельности

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.menu_main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()){ 
     case R.id.action: 
    //Do something 
      break; 

     default:break; 
    } 
    return false; 
} 

и в моем фрагменте

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

} 


@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()){ 
     case R.id.fragment_action: 
     //Do something 
      break; 
    } 
    return true; 
} 

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

  • Нет связанных вопросов^_^