java - Same Fragment appears in all tabs -


I have encountered a problem in my Android application when I added two tabs, I had two pieces. But the thing is that the same piece is visible on both tabs. The second piece is not visible here.

http://i60.tinypic.com/eu0kzs Png

< P> http://i60.tinypic.com/2uh0i1k.png

Here's my Your code for activity is:

  Public class DatabaseFiller extends activity {public zero onCreate (bundled savedInstanceState) {super.onCreate (savedInstanceState); StrictMode.ThreadPolicy Policy = New StrictMode.ThreadPolicy.Builder (). PermitAll () Build (); StrictMode.setThreadPolicy (policy); SetContentView (R.layout.rmactivity); ActionBoard ActionBar = Matching Actionbar (); ActionBar.setNavigationMode (ActionBar.NAVIGATION_MODE_TABS); Actionbars.SetSubsheets ("Made by Rohit Nandkumar"); / Actionbar Tab Searchbb = Actionbars Neiteab (). Set text ("search database"); Actionbars Tab Searchlist = Actionbar NEETAB (). Set test ("show show"); * / Actionbar. Tab Frag1 = actionBar.newTab () SetText ("Search Databases"); Actionbars Tab frog 2 = actionbars. NEETAB (). SetText ("Show list"); Piece volume 1 = new databasefileregrimate (); Piece volume 2 = new DeleteDBItems (); Frag1.setTabListener (New MyTabListener (fragment1)); Frag2.setTabListener (New MyTabListener (fragment2)); ActionBar.addTab (Frag1); ActionBar.addTab (Frag2); }}  

This is my complete list of mystical classes:

  package com.example.foodsaver2; Import android.app.ActionBar.Tab; Import android.app.ActionBar.TabListener; Import android.app.ActionBar; Import android.app.Fragment; Import Android.f. Fragmentation transactions; Public Class MyTabListener TabListener {implements the public piece piece; Public matablister (piece piece) {this.fragment = fragment; } @Override public void OnTabReselected (tab, FragmentTransaction feet) {// TODO Auto-generated method stub} @Override public void OnTabSelected (tab, FragmentTransaction feet) {// TODO Auto-generated method stub that (piece == null ) {// If not, then add immediate and activity to ft.add (android.R.id.content, fragment); } Else {// If it exists, then torn it. Attach it to show the piece; }} @Override public zero OnTabUnselected (tab, FragmentTransaction feet) {// TODO Auto-generated method stub if {// piece separately because another being attached Ftkdetach (piece) (BIT = null !); }}}  

What am I doing wrong here? Any help regarding this problem will be appreciated.

Start the listener, commit it separately to piece.

See the following modified code for help -

  Public MyTabListener (Activity activity, string tag, class & lt; t & gt; cls, bundle args) {activation = activity; MTag = Tag; MClass = CLS; Marz = Args; Fragment = mActivity.getFragmentManager (). FindFragmentByTag (mTag); If (piece! = NULL) {fragment Tronssekshn feet = Metrtaivitikjetragment Manager (). BeginTransaction (); Ft.detach (piece); Ft.commit (); }} Public void onTabSelected (tab, FragmentTransaction feet) {piece = Fragment.instantiate (mActivity, mClass.getName (), mArgs); Ft.add (android.r.id.content, fragment, mTag); } Public void tab (selected tab, slice transactions feet) {if (fragment! = Null) {ft.detach (fragment); }}  

Comments