简体   繁体   中英

Keep Fragments Synconized - Fragment Android

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM