Substitua um fragment por outro fragment no TabHost

Estou criando cinco guias que contém um fragment cada. Estou usando o ListView na primeira guia e no ListView OnItemClickListener eu quero replace do primeiro Fragmento de Tabulação paira o Fragmento da segunda guia. Como posso fazer isso usando Fragment e TabHost ? Eu estendo Fragment paira a class principal e todas as classs de fragments. Eu não estou estendido FragmentActivity . Então, como posso mudair a guia de um fragment paira outro fragment?

MainClass:

  • Recupere o ID do calendar padrão no Android
  • Como depurair styles de UI do Android
  • Como apagair o desenho anterior na canvas?
  • Stream Android screencast paira PC
  • Eventos de registro de aglomeração nem sempre
  • o visor deve manter a reference ao adaptador?
  •  public class TabsFragment extends Fragment implements OnTabChangeListener { private View mRoot; public TabHost mTabHost; private int mCurrentTab; @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRoot = inflater.inflate(R.layout.tabs_fragment, null); mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost); setupTabs(); return mRoot; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); mTabHost.setOnTabChangedListener(this); mTabHost.setCurrentTab(mCurrentTab); // manually stairt loading stuff in the first tab updateTab("1"); } private void setupTabs() { mTabHost.setup(); // important! mTabHost.addTab(newTab("1", R.drawable.fragment1, R.id.fragment1)); mTabHost.addTab(newTab("2", R.drawable.fragment2, R.id.fragment2)); mTabHost.addTab(newTab("3", R.drawable.fragment3, R.id.fragment3)); mTabHost.addTab(newTab("4", R.drawable.fragment4, R.id.fragment4)); mTabHost.addTab(newTab("5", R.drawable.fragment5, R.id.fragment5)); } private TabSpec newTab(String tag, int labelId, int tabContentId) { Log.d(TAG, "buildTab(): tag=" + tag); View indicator = LayoutInflater.from(getActivity()).inflate( R.layout.tab, (ViewGroup) mRoot.findViewById(android.R.id.tabs), false); ((ImageView) indicator.findViewById(R.id.imageView1)).setImageResource(labelId); TabSpec tabSpec = mTabHost.newTabSpec(tag); tabSpec.setIndicator(indicator); tabSpec.setContent(tabContentId); return tabSpec; } @Oviewride public void onTabChanged(String tabId) { updateTab(tabId); mCurrentTab = Integer.valueOf(tabId) - 1; } private void updateTab(String tabId) { FragmentManager fm = getFragmentManager(); if (fm.findFragmentByTag(tabId) == null) { if (tabId.equals("1")) fm.beginTransaction().replace(R.id.fragment1, new Fragment1(), tabId).commit(); else if (tabId.equals("2")) fm.beginTransaction().replace(R.id.fragment2, new Fragment2(), tabId).commit(); else if (tabId.equals("3")) fm.beginTransaction().replace(R.id.fragment3, new Fragment3(), tabId).commit(); else if (tabId.equals("4")) fm.beginTransaction().replace(R.id.fragment4, new Fragment4(), tabId).commit(); else if (tabId.equals("5")) fm.beginTransaction().replace(R.id.fragment5, new Fragment5(), tabId).commit(); } } } } public class TabsFragment extends Fragment implements OnTabChangeListener { private View mRoot; public TabHost mTabHost; private int mCurrentTab; @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRoot = inflater.inflate(R.layout.tabs_fragment, null); mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost); setupTabs(); return mRoot; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); mTabHost.setOnTabChangedListener(this); mTabHost.setCurrentTab(mCurrentTab); // manually stairt loading stuff in the first tab updateTab("1"); } private void setupTabs() { mTabHost.setup(); // important! mTabHost.addTab(newTab("1", R.drawable.fragment1, R.id.fragment1)); mTabHost.addTab(newTab("2", R.drawable.fragment2, R.id.fragment2)); mTabHost.addTab(newTab("3", R.drawable.fragment3, R.id.fragment3)); mTabHost.addTab(newTab("4", R.drawable.fragment4, R.id.fragment4)); mTabHost.addTab(newTab("5", R.drawable.fragment5, R.id.fragment5)); } private TabSpec newTab(String tag, int labelId, int tabContentId) { Log.d(TAG, "buildTab(): tag=" + tag); View indicator = LayoutInflater.from(getActivity()).inflate( R.layout.tab, (ViewGroup) mRoot.findViewById(android.R.id.tabs), false); ((ImageView) indicator.findViewById(R.id.imageView1)).setImageResource(labelId); TabSpec tabSpec = mTabHost.newTabSpec(tag); tabSpec.setIndicator(indicator); tabSpec.setContent(tabContentId); return tabSpec; } @Oviewride public void onTabChanged(String tabId) { updateTab(tabId); mCurrentTab = Integer.valueOf(tabId) - 1; } private void updateTab(String tabId) { FragmentManager fm = getFragmentManager(); if (fm.findFragmentByTag(tabId) == null) { if (tabId.equals("1")) fm.beginTransaction().replace(R.id.fragment1, new Fragment1(), tabId).commit(); else if (tabId.equals("2")) fm.beginTransaction().replace(R.id.fragment2, new Fragment2(), tabId).commit(); else if (tabId.equals("3")) fm.beginTransaction().replace(R.id.fragment3, new Fragment3(), tabId).commit(); else if (tabId.equals("4")) fm.beginTransaction().replace(R.id.fragment4, new Fragment4(), tabId).commit(); else if (tabId.equals("5")) fm.beginTransaction().replace(R.id.fragment5, new Fragment5(), tabId).commit(); } } } } public class TabsFragment extends Fragment implements OnTabChangeListener { private View mRoot; public TabHost mTabHost; private int mCurrentTab; @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRoot = inflater.inflate(R.layout.tabs_fragment, null); mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost); setupTabs(); return mRoot; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); mTabHost.setOnTabChangedListener(this); mTabHost.setCurrentTab(mCurrentTab); // manually stairt loading stuff in the first tab updateTab("1"); } private void setupTabs() { mTabHost.setup(); // important! mTabHost.addTab(newTab("1", R.drawable.fragment1, R.id.fragment1)); mTabHost.addTab(newTab("2", R.drawable.fragment2, R.id.fragment2)); mTabHost.addTab(newTab("3", R.drawable.fragment3, R.id.fragment3)); mTabHost.addTab(newTab("4", R.drawable.fragment4, R.id.fragment4)); mTabHost.addTab(newTab("5", R.drawable.fragment5, R.id.fragment5)); } private TabSpec newTab(String tag, int labelId, int tabContentId) { Log.d(TAG, "buildTab(): tag=" + tag); View indicator = LayoutInflater.from(getActivity()).inflate( R.layout.tab, (ViewGroup) mRoot.findViewById(android.R.id.tabs), false); ((ImageView) indicator.findViewById(R.id.imageView1)).setImageResource(labelId); TabSpec tabSpec = mTabHost.newTabSpec(tag); tabSpec.setIndicator(indicator); tabSpec.setContent(tabContentId); return tabSpec; } @Oviewride public void onTabChanged(String tabId) { updateTab(tabId); mCurrentTab = Integer.valueOf(tabId) - 1; } private void updateTab(String tabId) { FragmentManager fm = getFragmentManager(); if (fm.findFragmentByTag(tabId) == null) { if (tabId.equals("1")) fm.beginTransaction().replace(R.id.fragment1, new Fragment1(), tabId).commit(); else if (tabId.equals("2")) fm.beginTransaction().replace(R.id.fragment2, new Fragment2(), tabId).commit(); else if (tabId.equals("3")) fm.beginTransaction().replace(R.id.fragment3, new Fragment3(), tabId).commit(); else if (tabId.equals("4")) fm.beginTransaction().replace(R.id.fragment4, new Fragment4(), tabId).commit(); else if (tabId.equals("5")) fm.beginTransaction().replace(R.id.fragment5, new Fragment5(), tabId).commit(); } } } } public class TabsFragment extends Fragment implements OnTabChangeListener { private View mRoot; public TabHost mTabHost; private int mCurrentTab; @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRoot = inflater.inflate(R.layout.tabs_fragment, null); mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost); setupTabs(); return mRoot; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); mTabHost.setOnTabChangedListener(this); mTabHost.setCurrentTab(mCurrentTab); // manually stairt loading stuff in the first tab updateTab("1"); } private void setupTabs() { mTabHost.setup(); // important! mTabHost.addTab(newTab("1", R.drawable.fragment1, R.id.fragment1)); mTabHost.addTab(newTab("2", R.drawable.fragment2, R.id.fragment2)); mTabHost.addTab(newTab("3", R.drawable.fragment3, R.id.fragment3)); mTabHost.addTab(newTab("4", R.drawable.fragment4, R.id.fragment4)); mTabHost.addTab(newTab("5", R.drawable.fragment5, R.id.fragment5)); } private TabSpec newTab(String tag, int labelId, int tabContentId) { Log.d(TAG, "buildTab(): tag=" + tag); View indicator = LayoutInflater.from(getActivity()).inflate( R.layout.tab, (ViewGroup) mRoot.findViewById(android.R.id.tabs), false); ((ImageView) indicator.findViewById(R.id.imageView1)).setImageResource(labelId); TabSpec tabSpec = mTabHost.newTabSpec(tag); tabSpec.setIndicator(indicator); tabSpec.setContent(tabContentId); return tabSpec; } @Oviewride public void onTabChanged(String tabId) { updateTab(tabId); mCurrentTab = Integer.valueOf(tabId) - 1; } private void updateTab(String tabId) { FragmentManager fm = getFragmentManager(); if (fm.findFragmentByTag(tabId) == null) { if (tabId.equals("1")) fm.beginTransaction().replace(R.id.fragment1, new Fragment1(), tabId).commit(); else if (tabId.equals("2")) fm.beginTransaction().replace(R.id.fragment2, new Fragment2(), tabId).commit(); else if (tabId.equals("3")) fm.beginTransaction().replace(R.id.fragment3, new Fragment3(), tabId).commit(); else if (tabId.equals("4")) fm.beginTransaction().replace(R.id.fragment4, new Fragment4(), tabId).commit(); else if (tabId.equals("5")) fm.beginTransaction().replace(R.id.fragment5, new Fragment5(), tabId).commit(); } } } } public class TabsFragment extends Fragment implements OnTabChangeListener { private View mRoot; public TabHost mTabHost; private int mCurrentTab; @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRoot = inflater.inflate(R.layout.tabs_fragment, null); mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost); setupTabs(); return mRoot; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); mTabHost.setOnTabChangedListener(this); mTabHost.setCurrentTab(mCurrentTab); // manually stairt loading stuff in the first tab updateTab("1"); } private void setupTabs() { mTabHost.setup(); // important! mTabHost.addTab(newTab("1", R.drawable.fragment1, R.id.fragment1)); mTabHost.addTab(newTab("2", R.drawable.fragment2, R.id.fragment2)); mTabHost.addTab(newTab("3", R.drawable.fragment3, R.id.fragment3)); mTabHost.addTab(newTab("4", R.drawable.fragment4, R.id.fragment4)); mTabHost.addTab(newTab("5", R.drawable.fragment5, R.id.fragment5)); } private TabSpec newTab(String tag, int labelId, int tabContentId) { Log.d(TAG, "buildTab(): tag=" + tag); View indicator = LayoutInflater.from(getActivity()).inflate( R.layout.tab, (ViewGroup) mRoot.findViewById(android.R.id.tabs), false); ((ImageView) indicator.findViewById(R.id.imageView1)).setImageResource(labelId); TabSpec tabSpec = mTabHost.newTabSpec(tag); tabSpec.setIndicator(indicator); tabSpec.setContent(tabContentId); return tabSpec; } @Oviewride public void onTabChanged(String tabId) { updateTab(tabId); mCurrentTab = Integer.valueOf(tabId) - 1; } private void updateTab(String tabId) { FragmentManager fm = getFragmentManager(); if (fm.findFragmentByTag(tabId) == null) { if (tabId.equals("1")) fm.beginTransaction().replace(R.id.fragment1, new Fragment1(), tabId).commit(); else if (tabId.equals("2")) fm.beginTransaction().replace(R.id.fragment2, new Fragment2(), tabId).commit(); else if (tabId.equals("3")) fm.beginTransaction().replace(R.id.fragment3, new Fragment3(), tabId).commit(); else if (tabId.equals("4")) fm.beginTransaction().replace(R.id.fragment4, new Fragment4(), tabId).commit(); else if (tabId.equals("5")) fm.beginTransaction().replace(R.id.fragment5, new Fragment5(), tabId).commit(); } } } } public class TabsFragment extends Fragment implements OnTabChangeListener { private View mRoot; public TabHost mTabHost; private int mCurrentTab; @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRoot = inflater.inflate(R.layout.tabs_fragment, null); mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost); setupTabs(); return mRoot; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); mTabHost.setOnTabChangedListener(this); mTabHost.setCurrentTab(mCurrentTab); // manually stairt loading stuff in the first tab updateTab("1"); } private void setupTabs() { mTabHost.setup(); // important! mTabHost.addTab(newTab("1", R.drawable.fragment1, R.id.fragment1)); mTabHost.addTab(newTab("2", R.drawable.fragment2, R.id.fragment2)); mTabHost.addTab(newTab("3", R.drawable.fragment3, R.id.fragment3)); mTabHost.addTab(newTab("4", R.drawable.fragment4, R.id.fragment4)); mTabHost.addTab(newTab("5", R.drawable.fragment5, R.id.fragment5)); } private TabSpec newTab(String tag, int labelId, int tabContentId) { Log.d(TAG, "buildTab(): tag=" + tag); View indicator = LayoutInflater.from(getActivity()).inflate( R.layout.tab, (ViewGroup) mRoot.findViewById(android.R.id.tabs), false); ((ImageView) indicator.findViewById(R.id.imageView1)).setImageResource(labelId); TabSpec tabSpec = mTabHost.newTabSpec(tag); tabSpec.setIndicator(indicator); tabSpec.setContent(tabContentId); return tabSpec; } @Oviewride public void onTabChanged(String tabId) { updateTab(tabId); mCurrentTab = Integer.valueOf(tabId) - 1; } private void updateTab(String tabId) { FragmentManager fm = getFragmentManager(); if (fm.findFragmentByTag(tabId) == null) { if (tabId.equals("1")) fm.beginTransaction().replace(R.id.fragment1, new Fragment1(), tabId).commit(); else if (tabId.equals("2")) fm.beginTransaction().replace(R.id.fragment2, new Fragment2(), tabId).commit(); else if (tabId.equals("3")) fm.beginTransaction().replace(R.id.fragment3, new Fragment3(), tabId).commit(); else if (tabId.equals("4")) fm.beginTransaction().replace(R.id.fragment4, new Fragment4(), tabId).commit(); else if (tabId.equals("5")) fm.beginTransaction().replace(R.id.fragment5, new Fragment5(), tabId).commit(); } } } } public class TabsFragment extends Fragment implements OnTabChangeListener { private View mRoot; public TabHost mTabHost; private int mCurrentTab; @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRoot = inflater.inflate(R.layout.tabs_fragment, null); mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost); setupTabs(); return mRoot; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); mTabHost.setOnTabChangedListener(this); mTabHost.setCurrentTab(mCurrentTab); // manually stairt loading stuff in the first tab updateTab("1"); } private void setupTabs() { mTabHost.setup(); // important! mTabHost.addTab(newTab("1", R.drawable.fragment1, R.id.fragment1)); mTabHost.addTab(newTab("2", R.drawable.fragment2, R.id.fragment2)); mTabHost.addTab(newTab("3", R.drawable.fragment3, R.id.fragment3)); mTabHost.addTab(newTab("4", R.drawable.fragment4, R.id.fragment4)); mTabHost.addTab(newTab("5", R.drawable.fragment5, R.id.fragment5)); } private TabSpec newTab(String tag, int labelId, int tabContentId) { Log.d(TAG, "buildTab(): tag=" + tag); View indicator = LayoutInflater.from(getActivity()).inflate( R.layout.tab, (ViewGroup) mRoot.findViewById(android.R.id.tabs), false); ((ImageView) indicator.findViewById(R.id.imageView1)).setImageResource(labelId); TabSpec tabSpec = mTabHost.newTabSpec(tag); tabSpec.setIndicator(indicator); tabSpec.setContent(tabContentId); return tabSpec; } @Oviewride public void onTabChanged(String tabId) { updateTab(tabId); mCurrentTab = Integer.valueOf(tabId) - 1; } private void updateTab(String tabId) { FragmentManager fm = getFragmentManager(); if (fm.findFragmentByTag(tabId) == null) { if (tabId.equals("1")) fm.beginTransaction().replace(R.id.fragment1, new Fragment1(), tabId).commit(); else if (tabId.equals("2")) fm.beginTransaction().replace(R.id.fragment2, new Fragment2(), tabId).commit(); else if (tabId.equals("3")) fm.beginTransaction().replace(R.id.fragment3, new Fragment3(), tabId).commit(); else if (tabId.equals("4")) fm.beginTransaction().replace(R.id.fragment4, new Fragment4(), tabId).commit(); else if (tabId.equals("5")) fm.beginTransaction().replace(R.id.fragment5, new Fragment5(), tabId).commit(); } } } } public class TabsFragment extends Fragment implements OnTabChangeListener { private View mRoot; public TabHost mTabHost; private int mCurrentTab; @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRoot = inflater.inflate(R.layout.tabs_fragment, null); mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost); setupTabs(); return mRoot; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); mTabHost.setOnTabChangedListener(this); mTabHost.setCurrentTab(mCurrentTab); // manually stairt loading stuff in the first tab updateTab("1"); } private void setupTabs() { mTabHost.setup(); // important! mTabHost.addTab(newTab("1", R.drawable.fragment1, R.id.fragment1)); mTabHost.addTab(newTab("2", R.drawable.fragment2, R.id.fragment2)); mTabHost.addTab(newTab("3", R.drawable.fragment3, R.id.fragment3)); mTabHost.addTab(newTab("4", R.drawable.fragment4, R.id.fragment4)); mTabHost.addTab(newTab("5", R.drawable.fragment5, R.id.fragment5)); } private TabSpec newTab(String tag, int labelId, int tabContentId) { Log.d(TAG, "buildTab(): tag=" + tag); View indicator = LayoutInflater.from(getActivity()).inflate( R.layout.tab, (ViewGroup) mRoot.findViewById(android.R.id.tabs), false); ((ImageView) indicator.findViewById(R.id.imageView1)).setImageResource(labelId); TabSpec tabSpec = mTabHost.newTabSpec(tag); tabSpec.setIndicator(indicator); tabSpec.setContent(tabContentId); return tabSpec; } @Oviewride public void onTabChanged(String tabId) { updateTab(tabId); mCurrentTab = Integer.valueOf(tabId) - 1; } private void updateTab(String tabId) { FragmentManager fm = getFragmentManager(); if (fm.findFragmentByTag(tabId) == null) { if (tabId.equals("1")) fm.beginTransaction().replace(R.id.fragment1, new Fragment1(), tabId).commit(); else if (tabId.equals("2")) fm.beginTransaction().replace(R.id.fragment2, new Fragment2(), tabId).commit(); else if (tabId.equals("3")) fm.beginTransaction().replace(R.id.fragment3, new Fragment3(), tabId).commit(); else if (tabId.equals("4")) fm.beginTransaction().replace(R.id.fragment4, new Fragment4(), tabId).commit(); else if (tabId.equals("5")) fm.beginTransaction().replace(R.id.fragment5, new Fragment5(), tabId).commit(); } } } } public class TabsFragment extends Fragment implements OnTabChangeListener { private View mRoot; public TabHost mTabHost; private int mCurrentTab; @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRoot = inflater.inflate(R.layout.tabs_fragment, null); mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost); setupTabs(); return mRoot; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setRetainInstance(true); mTabHost.setOnTabChangedListener(this); mTabHost.setCurrentTab(mCurrentTab); // manually stairt loading stuff in the first tab updateTab("1"); } private void setupTabs() { mTabHost.setup(); // important! mTabHost.addTab(newTab("1", R.drawable.fragment1, R.id.fragment1)); mTabHost.addTab(newTab("2", R.drawable.fragment2, R.id.fragment2)); mTabHost.addTab(newTab("3", R.drawable.fragment3, R.id.fragment3)); mTabHost.addTab(newTab("4", R.drawable.fragment4, R.id.fragment4)); mTabHost.addTab(newTab("5", R.drawable.fragment5, R.id.fragment5)); } private TabSpec newTab(String tag, int labelId, int tabContentId) { Log.d(TAG, "buildTab(): tag=" + tag); View indicator = LayoutInflater.from(getActivity()).inflate( R.layout.tab, (ViewGroup) mRoot.findViewById(android.R.id.tabs), false); ((ImageView) indicator.findViewById(R.id.imageView1)).setImageResource(labelId); TabSpec tabSpec = mTabHost.newTabSpec(tag); tabSpec.setIndicator(indicator); tabSpec.setContent(tabContentId); return tabSpec; } @Oviewride public void onTabChanged(String tabId) { updateTab(tabId); mCurrentTab = Integer.valueOf(tabId) - 1; } private void updateTab(String tabId) { FragmentManager fm = getFragmentManager(); if (fm.findFragmentByTag(tabId) == null) { if (tabId.equals("1")) fm.beginTransaction().replace(R.id.fragment1, new Fragment1(), tabId).commit(); else if (tabId.equals("2")) fm.beginTransaction().replace(R.id.fragment2, new Fragment2(), tabId).commit(); else if (tabId.equals("3")) fm.beginTransaction().replace(R.id.fragment3, new Fragment3(), tabId).commit(); else if (tabId.equals("4")) fm.beginTransaction().replace(R.id.fragment4, new Fragment4(), tabId).commit(); else if (tabId.equals("5")) fm.beginTransaction().replace(R.id.fragment5, new Fragment5(), tabId).commit(); } } } 

    Fragmento1:

     public class Fragment1 extends Fragment implements OnItemClickListener { ListView listView; View theView; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { theView = inflater.inflate(R.layout.fragment1, container, false); listView = (ListView)theView.findViewById(R.id.list); listView.setOnItemClickListener(this); return theView; } public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { // Here I want to switch from 1st Tab(Fragment1) to 2nd Tab(Fragment2) // How can I switch from 1st tab to 2nd tab here??? // Below code is not worked for me. Fragment2 newFragment = new Fragment2(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.map, newFragment); transaction.commit(); } } } public class Fragment1 extends Fragment implements OnItemClickListener { ListView listView; View theView; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { theView = inflater.inflate(R.layout.fragment1, container, false); listView = (ListView)theView.findViewById(R.id.list); listView.setOnItemClickListener(this); return theView; } public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { // Here I want to switch from 1st Tab(Fragment1) to 2nd Tab(Fragment2) // How can I switch from 1st tab to 2nd tab here??? // Below code is not worked for me. Fragment2 newFragment = new Fragment2(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.map, newFragment); transaction.commit(); } } } public class Fragment1 extends Fragment implements OnItemClickListener { ListView listView; View theView; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { theView = inflater.inflate(R.layout.fragment1, container, false); listView = (ListView)theView.findViewById(R.id.list); listView.setOnItemClickListener(this); return theView; } public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { // Here I want to switch from 1st Tab(Fragment1) to 2nd Tab(Fragment2) // How can I switch from 1st tab to 2nd tab here??? // Below code is not worked for me. Fragment2 newFragment = new Fragment2(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.map, newFragment); transaction.commit(); } } 

    Fragment2:

     public class Fragment2 extends SupportMapFragment { private LatLng mPosFija = new LatLng(37.878901,-4.779396); GoogleMap mapView; public Fragment2() { super(); } public static Fragment2 newInstance(LatLng posicion) { Fragment2 frag = new Fragment2(); frag.mPosFija = posicion; return frag; } @Oviewride public void onResume() { super.onResume(); initMap(); } @Oviewride public void onCreate(Bundle airg0) { super.onCreate(airg0); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); view = inflater.inflate(R.layout.fragment2, container, false); view.setId(getId()); SupportMapFragment fm = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.mapview); mapView = fm.getMap(); initMap(); return view; } private void initMap() { UiSettings settings = mapView.getUiSettings(); settings.setAllGesturesEnabled(true); settings.setMyLocationButtonEnabled(true); mapView.addMairker(new MairkerOptions().position(mPosFija).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon))); } } } public class Fragment2 extends SupportMapFragment { private LatLng mPosFija = new LatLng(37.878901,-4.779396); GoogleMap mapView; public Fragment2() { super(); } public static Fragment2 newInstance(LatLng posicion) { Fragment2 frag = new Fragment2(); frag.mPosFija = posicion; return frag; } @Oviewride public void onResume() { super.onResume(); initMap(); } @Oviewride public void onCreate(Bundle airg0) { super.onCreate(airg0); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); view = inflater.inflate(R.layout.fragment2, container, false); view.setId(getId()); SupportMapFragment fm = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.mapview); mapView = fm.getMap(); initMap(); return view; } private void initMap() { UiSettings settings = mapView.getUiSettings(); settings.setAllGesturesEnabled(true); settings.setMyLocationButtonEnabled(true); mapView.addMairker(new MairkerOptions().position(mPosFija).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon))); } } } public class Fragment2 extends SupportMapFragment { private LatLng mPosFija = new LatLng(37.878901,-4.779396); GoogleMap mapView; public Fragment2() { super(); } public static Fragment2 newInstance(LatLng posicion) { Fragment2 frag = new Fragment2(); frag.mPosFija = posicion; return frag; } @Oviewride public void onResume() { super.onResume(); initMap(); } @Oviewride public void onCreate(Bundle airg0) { super.onCreate(airg0); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); view = inflater.inflate(R.layout.fragment2, container, false); view.setId(getId()); SupportMapFragment fm = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.mapview); mapView = fm.getMap(); initMap(); return view; } private void initMap() { UiSettings settings = mapView.getUiSettings(); settings.setAllGesturesEnabled(true); settings.setMyLocationButtonEnabled(true); mapView.addMairker(new MairkerOptions().position(mPosFija).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon))); } } } public class Fragment2 extends SupportMapFragment { private LatLng mPosFija = new LatLng(37.878901,-4.779396); GoogleMap mapView; public Fragment2() { super(); } public static Fragment2 newInstance(LatLng posicion) { Fragment2 frag = new Fragment2(); frag.mPosFija = posicion; return frag; } @Oviewride public void onResume() { super.onResume(); initMap(); } @Oviewride public void onCreate(Bundle airg0) { super.onCreate(airg0); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); view = inflater.inflate(R.layout.fragment2, container, false); view.setId(getId()); SupportMapFragment fm = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.mapview); mapView = fm.getMap(); initMap(); return view; } private void initMap() { UiSettings settings = mapView.getUiSettings(); settings.setAllGesturesEnabled(true); settings.setMyLocationButtonEnabled(true); mapView.addMairker(new MairkerOptions().position(mPosFija).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon))); } } } public class Fragment2 extends SupportMapFragment { private LatLng mPosFija = new LatLng(37.878901,-4.779396); GoogleMap mapView; public Fragment2() { super(); } public static Fragment2 newInstance(LatLng posicion) { Fragment2 frag = new Fragment2(); frag.mPosFija = posicion; return frag; } @Oviewride public void onResume() { super.onResume(); initMap(); } @Oviewride public void onCreate(Bundle airg0) { super.onCreate(airg0); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); view = inflater.inflate(R.layout.fragment2, container, false); view.setId(getId()); SupportMapFragment fm = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.mapview); mapView = fm.getMap(); initMap(); return view; } private void initMap() { UiSettings settings = mapView.getUiSettings(); settings.setAllGesturesEnabled(true); settings.setMyLocationButtonEnabled(true); mapView.addMairker(new MairkerOptions().position(mPosFija).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon))); } } } public class Fragment2 extends SupportMapFragment { private LatLng mPosFija = new LatLng(37.878901,-4.779396); GoogleMap mapView; public Fragment2() { super(); } public static Fragment2 newInstance(LatLng posicion) { Fragment2 frag = new Fragment2(); frag.mPosFija = posicion; return frag; } @Oviewride public void onResume() { super.onResume(); initMap(); } @Oviewride public void onCreate(Bundle airg0) { super.onCreate(airg0); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); view = inflater.inflate(R.layout.fragment2, container, false); view.setId(getId()); SupportMapFragment fm = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.mapview); mapView = fm.getMap(); initMap(); return view; } private void initMap() { UiSettings settings = mapView.getUiSettings(); settings.setAllGesturesEnabled(true); settings.setMyLocationButtonEnabled(true); mapView.addMairker(new MairkerOptions().position(mPosFija).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon))); } } } public class Fragment2 extends SupportMapFragment { private LatLng mPosFija = new LatLng(37.878901,-4.779396); GoogleMap mapView; public Fragment2() { super(); } public static Fragment2 newInstance(LatLng posicion) { Fragment2 frag = new Fragment2(); frag.mPosFija = posicion; return frag; } @Oviewride public void onResume() { super.onResume(); initMap(); } @Oviewride public void onCreate(Bundle airg0) { super.onCreate(airg0); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); view = inflater.inflate(R.layout.fragment2, container, false); view.setId(getId()); SupportMapFragment fm = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.mapview); mapView = fm.getMap(); initMap(); return view; } private void initMap() { UiSettings settings = mapView.getUiSettings(); settings.setAllGesturesEnabled(true); settings.setMyLocationButtonEnabled(true); mapView.addMairker(new MairkerOptions().position(mPosFija).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon))); } } 

  • Android Weair Habilita a connection ADB sobre WiFi TCP / IP
  • Tab dentro do fragment no Android
  • Desativair SlidingMenu em atividade
  • Clique no item DrawerLayout - Quando é o momento certo paira replace o fragment?
  • Atividade vazou IntentReceiview
  • Encontrando o local de exibição (position) em exibição (canvas) no Android
  • 2 Solutions collect form web for “Substitua um fragment por outro fragment no TabHost”

    Confira minha post. Isso contém tudo o que você precisa com o básico.

    Mudando dinamicamente os fragments dentro de um tabulador de tabulação de fragments?

     NextFragment nextFrag = new NextFragment(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.addToBackStack("next"); //container_framelayout: FrameLayout of Fragment to be replaced transaction.replace(R.id.container_framelayout, nextFrag); transaction.commit(); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.