0

I have an Android App using Fragments to create a sliding view. I have 5 "Buttons" represented by FrameLayouts with content in them in Fragment A and Fragment B.

When clicking a Layout it turn green for a few seconds, and the others don't in that space of time:

c05.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (Storage.isWaiting)
                    return;

                Storage.isWaiting = true;
                Toast.makeText(getActivity().getApplicationContext(), "Text abc 123", Toast.LENGTH_LONG).show();
                c05.setBackgroundColor(Color.parseColor("#ff408c3a"));

                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        c05.setBackgroundColor(Color.parseColor("#393939"));
                        Storage.isWaiting = false;
                    }
                }, 3000);
            }
        });

I now need the to fragments to "syncronize" in a way that when i press button c01 in Fragment A c01 in Fragment B becomes green as well.

Do you have any Ideas how to do that?

Xlaech
  • 456
  • 3
  • 19
  • Your question is not clear. Still what I understand is that if you change color by clicking a button in fragment A, then other fragments should also change to that color. If this is so?.. Try saving color value in shared preferences, and when you load any preference, try checking the color value from that shared prefernce and set it as background color. Initially set the default color in sharepreference. – Harish Vats Sep 04 '15 at 09:35

1 Answers1

0

From what i can understand you basically want to communicate between two fragments. The basic rule is to communicate via the container activity and if possible by using interfaces.

Please follow an earlier post of mine here.

Community
  • 1
  • 1
Kaveesh Kanwal
  • 1,753
  • 17
  • 16
  • Looks interesting. **I hoped there would be a way to directly access the "button" in the other fragment**. But i'll try to get it done that way. – Xlaech Sep 04 '15 at 11:11
  • the way that i am suggesting you is the best and the most modular approach. – Kaveesh Kanwal Sep 04 '15 at 11:13