简体   繁体   English

保持片段同步-Fragment Android

[英]Keep Fragments Synconized - Fragment Android

I have an Android App using Fragments to create a sliding view. 我有一个使用Fragments创建滑动视图的Android应用。 I have 5 "Buttons" represented by FrameLayouts with content in them in Fragment A and Fragment B. 我有5个由FrameLayouts表示的“按钮”,其中的内容在片段A和片段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. 我现在需要to片段以“同步”的方式,当我按下片段A中的按钮c01时,片段B中的c01也变为绿色。

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 . 在这里关注我的早期帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从嵌套片段android中的backstack中删除片段 - Remove fragment from backstack in nested fragments android 调用时加载片段,并在切换到另一个片段/活动时保留 - Load fragments when call it and keep when switch to another fragment/activity Android片段-编辑另一个片段的文本 - Android Fragments - Edit Text Of Another Fragment Android Studio 中片段的 InflateException、Fragment$InstantiationException - InflateException, Fragment$InstantiationException for Fragments in Android Studio 每当我重新单击或导航到下一个片段时,我的片段都会不断重新创建 - My fragments keep recreating whenever I reclick or navigate to the next fragment 如何跟踪有关Android中片段的信息 - How to keep track of information regarding fragments in Android Android:保持片段在后台运行 - Android: Keep fragment running in the background 滑块菜单的Android片段,其中的选项卡内部有片段 - Android Fragment for Slider Menu which has Fragments inside for Tabs Map 片段在 Android Studio 之间切换时不隐藏片段 - Map fragment is not hidden when switch between fragments Android Studio 如何使用BaseAdapter将子片段添加到Android中的片段 - How can I add child fragments to a fragment in Android using a BaseAdapter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM