Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Things are in fact easy (I'm working with API level 14) and to remember it is I called the listener class <code>SimpleTabListener</code>.</p> <pre><code> public void OnTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { fragmentTransaction.Add(Resource.Id.fragment_container, fragment, typeof(T).Name); } public void OnTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { fragmentTransaction.Remove(fragment); } </code></pre> <p>I have been interested by your problem because I thought tab switching did not work right as android tutorial demonstrates. In fact I made a mistake when updating tab views and lost several hours searching a solution in a wrong direction. I saw your other questions on stackoverflow about tabs, and I'm thinking you were in a similar situation ;-) .</p> <p>EDIT: In fact, it seems that from android 3.2 attach/detach is a better idea when switching tabs as the fragment is kept in FragmentManager and the view removed. Previous methods are then:</p> <pre><code> public void OnTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { // Allows the view to be refreshed fragmentTransaction.Detach(fragment); fragmentTransaction.Attach(fragment); } public void OnTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { if (fragment == null) { fragment = Fragment.Instantiate(context, typeof(T).Namespace.ToLower() + "." + typeof(T).Name); fragmentTransaction.Add(Resource.Id.fragment_container, fragment); } else { fragmentTransaction.Attach(fragment); } } public void OnTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { if (fragment != null) { fragmentTransaction.Detach(fragment); } } </code></pre> <p><a href="http://daniel-codes.blogspot.fr/2012/06/fragment-transactions-reference.html" rel="nofollow">This blog post</a> is very interesting about the subject.</p>
    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.
    1. VO
      singulars
      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