I have data passing between two fragments:
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 also tried this as follows:
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 method transmits data, but still overlaps the screens, and the second method does not transmit data and overlaps the screens. After I complete the transaction, I see that my tab is still on the second, when it should be on the first. (I understood, because I replace it, therefore).
Is there a way to transfer data to another fragment and move it to another tab without overlapping?
This 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 am doing data transfer at the push of a button.
thanks
UPDATE
Both methods work. Something on the NewFragment side. They still overlap, however
android android-fragments
Bigt
source share