I have my data passing between two fragments like so:
Fragment newFragment = new NewFragment();
Bundle data = new Bundle();
data.putString("number", number[1]);
newFragment.setArguments(data);
getFragmentManager().beginTransaction().add(android.R.id.content, newFragment).attach(newFragment).commit();
I have also tried it this way:
Fragment newFragment = new NewFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction;
Bundle data = new Bundle();
data.putString("number", number[1]);
newFragment.setArguments(data);
transaction.replace(android.R.id.content, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
The first way passes the data but still overlaps the screens and the second way doesn't pass the data and overlaps the screens. After I commit the transaction I see that my tab is still on the 2nd one when it should be on the 1st one. (I figured since I am replacing it that is why).
Is there a way to pass data to another fragment and have it go to the other fragment tab without overlap?
Here is how I usually switch between fragments
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
mFragment = new CurrentFragment();
ft.add(android.R.id.content, mFragment);
ft.attach(mFragment);
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
ft.remove(mFragment);
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
PS I do the data transfer in a button click.
Thanks
UPDATE
Both ways work. Something on the NewFragment side. They still overlap however