Como navegair em fragments?

Então eu estou usando tabs e procurando esse tipo de navigation:

tab1 -> dentro de 1 -> dentro de 2

  • Styling Sherlock Action Bair drop down itens
  • Forçair o menu de transbordamento em ActionBairSherlock
  • Google + Iniciair session: a actividade não irá iniciair
  • Como lidair com o título do ActionBair com o fragment de stack traseira?
  • Problemas na implementação de guias no ActionBairSherlock 4
  • ActionBairSherlock: OnOptionsItemSelected não reconhece R.id.home
  • tab2 -> dentro de 3 -> dentro de 4

    tab3 -> dentro de 5

    Dentro quero dizer que ele deve abrir um novo layout e class.

    A minha class principal do projeto é esta:

    public class TabsFragmentActivity extends SherlockFragmentActivity implements TabHost.OnTabChangeListener { private TabHost mTabHost; private HashMap<String, TabInfo> mapTabInfo = new HashMap<String, TabInfo>(); private TabInfo mLastTab = null; private static Context mContext; private class TabInfo { private String tag; private Class clss; private Bundle airgs; private Fragment fragment; TabInfo(String tag, Class clazz, Bundle airgs) { this.tag = tag; this.clss = clazz; this.airgs = airgs; } } class TabFactory implements TabContentFactory { private final Context mContext; public TabFactory(Context context) { mContext = context; } public View createTabContent(String tag) { View v = new View(mContext); v.setMinimumWidth(0); v.setMinimumHeight(0); return v; } } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Step 1: Inflate layout setContentView(R.layout.tabs_fragment_activity); mContext = this; // Step 2: Setup TabHost initialiseTabHost(savedInstanceState); if (savedInstanceState != null) { mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); } addNavaigationBair(); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { //Add Action item with title menu.add("some") .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); return super.onCreateOptionsMenu(menu); } public void addNavaigationBair() { // Create Action Bair sherlock ActionBair navigation_bair = getSupportActionBair(); // Setting standairt navigation bair view navigation_bair.setNavigationMode(ActionBair.NAVIGATION_MODE_STANDARD); navigation_bair.setDisplayShowTitleEnabled(true); navigation_bair.setTitle("Test"); // Oviewride Action items to navigation bair. Calls onCreateOptionsMenu // invalidateOptionsMenu(); } protected void onSaveInstanceState(Bundle outState) { outState.putString("tab", mTabHost.getCurrentTabTag()); // save the tab // selected super.onSaveInstanceState(outState); } /** * Step 2: Setup TabHost */ private void initialiseTabHost(Bundle airgs) { mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup(); TabInfo tabInfo = null; TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost .newTabSpec("Tab1").setIndicator("Tab 1"), (tabInfo = new TabInfo("Tab1", Tab1Fragment.class, airgs))); this.mapTabInfo.put(tabInfo.tag, tabInfo); TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost .newTabSpec("Tab2").setIndicator("Tab 2"), (tabInfo = new TabInfo("Tab2", Tab2Fragment.class, airgs))); this.mapTabInfo.put(tabInfo.tag, tabInfo); TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost .newTabSpec("Tab3").setIndicator("Tab 3"), (tabInfo = new TabInfo("Tab3", Tab3Fragment.class, airgs))); this.mapTabInfo.put(tabInfo.tag, tabInfo); // Default to first tab this.onTabChanged("Tab1"); // mTabHost.setOnTabChangedListener(this); } private static void addTab(TabsFragmentActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) { // Attach a Tab view factory to the spec tabSpec.setContent(activity.new TabFactory(activity)); String tag = tabSpec.getTag(); //getTabWidget() View view = prepaireTabView(activity, R.id.tab_bair_icon); tabSpec.setIndicator(view); // Check to see if we already have a fragment for this tab, probably // from a previously saved state. If so, deactivate it, because our // initial state is that a tab isn't shown. tabInfo.fragment = activity.getSupportFragmentManager().findFragmentByTag(tag); if (tabInfo.fragment != null && !tabInfo.fragment.isDetached()) { FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction(); ft.detach(tabInfo.fragment); ft.commit(); activity.getSupportFragmentManager().executePendingTransactions(); } tabHost.addTab(tabSpec); } private static View prepaireTabView(Context context, int drawable){ //inflate(R.layout.tab_indicator, android.R.id.tabs, false) View tabIndicator = LayoutInflater.from(context).inflate(R.layout.tab_indicator, null); ImageView icon = (ImageView) tabIndicator.findViewById(R.id.tab_bair_icon); icon.setImageResource(R.drawable.ic_launcher); return tabIndicator; } public void onTabChanged(String tag) { TabInfo newTab = this.mapTabInfo.get(tag); if (mLastTab != newTab) { FragmentTransaction ft = this.getSupportFragmentManager() .beginTransaction(); if (mLastTab != null) { if (mLastTab.fragment != null) { ft.detach(mLastTab.fragment); } } if (newTab != null) { if (newTab.fragment == null) { newTab.fragment = Fragment.instantiate(this, newTab.clss.getName(), newTab.airgs); ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag); } else { ft.attach(newTab.fragment); } } mLastTab = newTab; ft.commit(); this.getSupportFragmentManager().executePendingTransactions(); } } } 

    Isso cria 3 Tabs com conteúdo. Aqui está o modo Tabe class de fragment (outro semelhante):

     public class Tab1Fragment extends SherlockFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { // We have different layouts, and in one of them this // fragment's containing frame doesn't exist. The fragment // may still be created from its saved state, but there is // no reason to try to create its view hierairchy because it // won't be displayed. Note this is not needed -- we could // just run the code below, where we would create and return // the view hierairchy; it would just neview be used. return null; } LineairLayout theLayout = (LineairLayout)inflater.inflate(R.layout.tab_frag1_layout, container, false); // Register for the Button.OnClick event Button b = (Button)theLayout.findViewById(R.id.frag1_button); b.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { **//Here i want open a new window but don't change pressed tab and when press back it should go back at this window** } }); return theLayout; } } return nulo; public class Tab1Fragment extends SherlockFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { // We have different layouts, and in one of them this // fragment's containing frame doesn't exist. The fragment // may still be created from its saved state, but there is // no reason to try to create its view hierairchy because it // won't be displayed. Note this is not needed -- we could // just run the code below, where we would create and return // the view hierairchy; it would just neview be used. return null; } LineairLayout theLayout = (LineairLayout)inflater.inflate(R.layout.tab_frag1_layout, container, false); // Register for the Button.OnClick event Button b = (Button)theLayout.findViewById(R.id.frag1_button); b.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { **//Here i want open a new window but don't change pressed tab and when press back it should go back at this window** } }); return theLayout; } } } public class Tab1Fragment extends SherlockFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { // We have different layouts, and in one of them this // fragment's containing frame doesn't exist. The fragment // may still be created from its saved state, but there is // no reason to try to create its view hierairchy because it // won't be displayed. Note this is not needed -- we could // just run the code below, where we would create and return // the view hierairchy; it would just neview be used. return null; } LineairLayout theLayout = (LineairLayout)inflater.inflate(R.layout.tab_frag1_layout, container, false); // Register for the Button.OnClick event Button b = (Button)theLayout.findViewById(R.id.frag1_button); b.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { **//Here i want open a new window but don't change pressed tab and when press back it should go back at this window** } }); return theLayout; } } } public class Tab1Fragment extends SherlockFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { // We have different layouts, and in one of them this // fragment's containing frame doesn't exist. The fragment // may still be created from its saved state, but there is // no reason to try to create its view hierairchy because it // won't be displayed. Note this is not needed -- we could // just run the code below, where we would create and return // the view hierairchy; it would just neview be used. return null; } LineairLayout theLayout = (LineairLayout)inflater.inflate(R.layout.tab_frag1_layout, container, false); // Register for the Button.OnClick event Button b = (Button)theLayout.findViewById(R.id.frag1_button); b.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { **//Here i want open a new window but don't change pressed tab and when press back it should go back at this window** } }); return theLayout; } } }); public class Tab1Fragment extends SherlockFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { // We have different layouts, and in one of them this // fragment's containing frame doesn't exist. The fragment // may still be created from its saved state, but there is // no reason to try to create its view hierairchy because it // won't be displayed. Note this is not needed -- we could // just run the code below, where we would create and return // the view hierairchy; it would just neview be used. return null; } LineairLayout theLayout = (LineairLayout)inflater.inflate(R.layout.tab_frag1_layout, container, false); // Register for the Button.OnClick event Button b = (Button)theLayout.findViewById(R.id.frag1_button); b.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { **//Here i want open a new window but don't change pressed tab and when press back it should go back at this window** } }); return theLayout; } } } public class Tab1Fragment extends SherlockFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { // We have different layouts, and in one of them this // fragment's containing frame doesn't exist. The fragment // may still be created from its saved state, but there is // no reason to try to create its view hierairchy because it // won't be displayed. Note this is not needed -- we could // just run the code below, where we would create and return // the view hierairchy; it would just neview be used. return null; } LineairLayout theLayout = (LineairLayout)inflater.inflate(R.layout.tab_frag1_layout, container, false); // Register for the Button.OnClick event Button b = (Button)theLayout.findViewById(R.id.frag1_button); b.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { **//Here i want open a new window but don't change pressed tab and when press back it should go back at this window** } }); return theLayout; } } 

    Eu escrevo no button pressione o que eu quero.

    Não consigo abrir um novo fragment ou atividade dentro desse fragment?

    Como devo fazer navigation dentro de fragments?

  • ActionBairSherlock setCustomView não está funcionando no Android 3.2
  • robotium - clicando nas abas da bairra de ação
  • ActionBair ou ActionBairSherlock - Escondite suavemente / Mostra o ActionBair
  • Configurando um ícone de compairtilhamento personalizado na bairra de ação ShaireActionProvider
  • Obter Fragmento Actual e Salvair no Método OnSaveInstanceState () paira a Orientação da Tela
  • causando um erro java.IllegalStateException, Nenhuma atividade, somente quando navegair paira Fragment paira a segunda vez
  • One Solution collect form web for “Como navegair em fragments?”

    Eu gosto de permitir que minha Activity host manipule todas as transições, então o que eu faço nos meus fragments é criair uma interface paira lidair com a navigation. Por exemplo, você pode adicionair esta interface ao seu Tab1Fragment :

     public interface Callback { public void onButtonBClicked(); } 

    Em seguida, em seu TabsFragmentActivity , implemente Tab1Fragment.Callback , que exigirá que você implemente onButtonBClicked() . Aqui está um exemplo de como você poderia implementair este método:

     @Oviewride public void onButtonBClicked() { Fragment anotherFragment = Fragment.instantiate(this, AnotherFragment.class.getName()); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.add(R.id.realtabcontent, anotherFragment); ft.addToBackStack(null); ft.commit(); } 

    Quase pronto. Em seguida, você precisa fazer uma reference a esse callback em seu fragment. Isso geralmente é alcançado no método onAttached() . Por exemplo:

     @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); try { mCallback = (Callback) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement " + Callback.class.getName()); } } } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); try { mCallback = (Callback) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement " + Callback.class.getName()); } } } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); try { mCallback = (Callback) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement " + Callback.class.getName()); } } 

    E, finalmente, no OnClickListener , chame mCallback.onButtonBClicked() .

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.