0

I have a main Activity which contains two Fragments (Each in it's own activity) as ActionTabListener

enter image description here

Everytime I hit the Calculate button I want the information to append on top of what's already under Display Result activity textbox and not overwrite. I tried SharedPreference, but it only works to setText() but .append() doesn't work.

The TextBox is initialized under the Display Trip as

private EditText showLog;

Should I change it to private?

How do I transfer information between the two activities without losing them within the duration of the application in the memory?

Si8
  • 9,141
  • 22
  • 109
  • 221
  • 1
    Create a class that holds this information and pass an instance of it as you wish. – m0skit0 Jul 30 '13 at 14:39
  • Would it be possible to show an example? – Si8 Jul 30 '13 at 14:40
  • I can show how to pass an instance between two other objects, but I don't have time to make a full Fragment example. Anyway, Fragments are instances, so the concept is the same. – m0skit0 Jul 30 '13 at 14:47

1 Answers1

1

Try this,

 Practice2 newFragment = new Practice2();

                bundle.putString("id", "Information");
                newFragment.setArguments(bundle);

                android.support.v4.app.FragmentManager fragmentManager = getFragmentManager();
                android.support.v4.app.FragmentTransaction transaction = fragmentManager
                        .beginTransaction();

                transaction.replace(R.id.llhome, newFragment);

                // Commit the transaction
                transaction.commit();

and replace the current version of display result with it's self but with the information and if you want you can attach multiple bundles for each string you want to show.

Cam Connor
  • 1,231
  • 2
  • 25
  • 40
  • Is that going in the Display Result activity or the Current Trip activity? I am taking one string which has multiple variables and sending it to Display Result activity. – Si8 Jul 30 '13 at 14:47
  • @SiKni8 If you set it to replace the Display Result Fragment Activity (set Practice2 to the name of the Display Result Activity class) it should replace that screen and not your current one – Cam Connor Jul 30 '13 at 15:18
  • Thanks. One issue I have is switching between the tab resets my textboxes and radio selects. How do I prevent that? – Si8 Jul 30 '13 at 19:10
  • 1
    @SiKni8 How are your tabs set up? – Cam Connor Jul 30 '13 at 20:40
  • Please visit http://stackoverflow.com/questions/17956973/saving-instance-to-avoid-losing-data-switching-between-tab for the question, do if you answer, you can get credit. – Si8 Jul 30 '13 at 20:43