Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing data between two fragments
    primarykey
    data
    text
    <p>I have two fragments, declared in separate classes - AFragment and BFragment. My MainActivity looks somewhat like this:</p> <pre><code>public class MainActivity extends SherlockFragmentActivity implements ActionBar.TabListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab firstTab = getSupportActionBar().newTab().setText("Fragment A"); ActionBar.Tab secondTab = getSupportActionBar().newTab().setText("Fragment B"); SherlockFragment firstFragment = new AFragment(); SherlockFragment secondFragment = new BFragment(); firstTab.setTabListener(this); secondTab.setTabListener(this); getSupportActionBar().addTab(firstTab); getSupportActionBar().addTab(secondTab); } @Override public void onTabReselected(Tab tab, FragmentTransaction ft) { } @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { switch (tab.getPosition()) { case 0: ft.replace(R.id.fragment_container, new AFragment()); break; case 1: ft.replace(R.id.fragment_container, new BFragment()); break; } Toast.makeText(this, tab.getText(), Toast.LENGTH_LONG).show(); } @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { } } </code></pre> <p>My question is, how do I pass a variable - say an integer - between my two fragments? For example, I'd press a button in the first fragment, and a particular integer would appear in a TextView in the second one.</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.
 

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