Note that there are some explanatory texts on larger screens.

plurals
  1. POonTabSelected not refreshing the fragment
    primarykey
    data
    text
    <p>Hi i am trying to develop an action bar navigation screen in which i m displaying two tabs.I am activating the fragments in onTabselected listener. But until i call fragementtransaction.commit() changes are not reflecting.It works only one time, i mean, if i switch to tab2 and comeback to tab1 again, the fragment is not refreshed.When switched to tab2, the content of tab2 is drawn on top of the tab1, looks like overlapping. i m posting my code here, please help me in solving this issue.</p> <p>Here is my Class:</p> <pre><code>public class ContentActivity extends FragmentActivity { @Override protected void onCreate(Bundle arg0) { this.requestWindowFeature(Window.FEATURE_ACTION_BAR); // this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, // WindowManager.LayoutParams.FLAG_DIM_BEHIND); //this.getWindow().setDimAmount((float) 30.0); LayoutParams params = this.getWindow().getAttributes(); params.height = LayoutParams.WRAP_CONTENT; //fixed height params.width = LayoutParams.MATCH_PARENT; //fixed width this.getWindow().setGravity(Gravity.START); this.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); super.onCreate(arg0); setContentView(R.layout.layout_content); ActionBar actionbar = getActionBar(); actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab BookMarkTab = actionbar.newTab().setText("BookMarks"); ActionBar.Tab NotesTab = actionbar.newTab().setText("Notes"); // Fragment bookMarkFragment = new BookMarkFragment(); //Fragment notesFragment = new NotesFragment(); BookMarkTab.setTabListener(new ContentTabListner(BookMarkFragment.class,"BookMarks")); NotesTab.setTabListener(new ContentTabListner(NotesFragment.class,"Notes")); actionbar.addTab(BookMarkTab); actionbar.addTab(NotesTab); } class ContentTabListner implements ActionBar.TabListener { private Fragment fragment; private Class mclz; private String mTag; android.support.v4.app.FragmentTransaction fft = ContentActivity.this .getSupportFragmentManager().beginTransaction(); public ContentTabListner(Class clazz,String tag) { mclz = clazz; mTag = tag; fragment = ContentActivity.this.getSupportFragmentManager().findFragmentByTag(mTag); if (fragment != null &amp;&amp; !fragment.isDetached()) { android.support.v4.app.FragmentTransaction ft = ContentActivity.this.getSupportFragmentManager().beginTransaction(); ft.detach(fragment); ft.commit(); } } @Override public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) { } @Override public void onTabSelected(Tab tab, android.app.FragmentTransaction ft) { if(fragment == null){ fragment = Fragment.instantiate(ContentActivity.this, mclz.getName(),null); fft.add(android.R.id.content,fragment, mTag); fft.commit(); }else{ fft.attach(fragment); } } @Override public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) { if(fragment != null){ fft.detach(fragment); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload