Note that there are some explanatory texts on larger screens.

plurals
  1. PORun code in ActionBar Tab Fragment when tab is removed
    primarykey
    data
    text
    <p>I've got Fragment ActionBar Tabs with an TabListener attached to every tab. In my main activity I got a delete tab button as follows:</p> <pre><code>@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId() case R.id.closeTab: closeTab(); return true; default: return super.onOptionsItemSelected(item); } } public void closeTab() { if(getActionBar().getTabCount() &gt; 1) { Tab tab = getActionBar().getSelectedTab(); getActionBar().removeTab(tab); } } </code></pre> <p>What I'm trying to accomplish is to run some code in my tab-fragment before it gets removed. I could place this in the fragments <code>onDestroyView()</code> or <code>onDestroy()</code> but I only whant to run this code when I press my delete tab button. I have checked the documentation for the <code>TabListener</code> but it seems like TabListener only listens to selectionchanges. My TabListener:</p> <pre><code>public TabListener(Activity a, String t, Class&lt;T&gt; c) { activity = a; tag = t; myClass = c; } /* The following are each of the ActionBar.TabListener callbacks */ public void onTabSelected(Tab tab, FragmentTransaction ft) { // Check if the fragment is already initialized if (fragment == null) { // If not, instantiate and add it to the activity fragment = Fragment.instantiate(activity, myClass.getName()); ft.add(android.R.id.content, fragment, tag); } else { // If it exists, simply attach it in order to show it ft.attach(fragment); } } public void onTabUnselected(Tab tab, FragmentTransaction ft) { if (fragment != null) { // Detach the fragment, because another one is being attached ft.detach(fragment); } } public void onTabReselected(Tab tab, FragmentTransaction ft) { } </code></pre> <p><strong>To clarify my question</strong>: How can I run code in my Fragment before the tab is removed?</p>
    singulars
    1. This table or related slice is empty.
    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