简体   繁体   English

片段中更新微调器活动中的数据并刷新

[英]Update data from spinner activity in fragment and refresh

I have main activity like this: 我有这样的主要活动:

MainActivity and ExampleFragment MainActivity和ExampleFragment

I need to update my fragment when some one change something in spinner. 当有人在微调器中更改某些内容时,我需要更新片段。 I know i can use interfaces, and im using it in my application but in this case i cant do that. 我知道我可以使用接口,并且即时通讯在我的应用程序中使用它,但是在这种情况下,我无法做到这一点。 I searched some many topics in stackoverflow and there i found only this: 我在stackoverflow中搜索了许多主题,在这里我仅发现了以下内容:

                        if (myFragment.getArguments() != null) {
                            myFragment.getArguments().putParcelable(Constants.USER,user);
                            myFragment.getArguments().putParcelable(Constants.PATIENT,pickedPatient);
                        }

I was trying detach and then attach my fragment to refresh, but data in bundle is not updated, and my fragment is just empty. 我尝试分离,然后将片段附加以刷新,但是bundle中的数据未更新,并且片段为空。 I checked my logs and old data is still available. 我检查了日志,仍然可以使用旧数据。

Is there any solution for that problem? 有什么解决办法吗? Or can I access my toolbar with spinner in my fragments and then update data in whole activity? 还是可以在片段中使用微调框访问我的工具栏,然后在整个活动中更新数据?

Some example with my another fragment here: 下面是我的另一个片段的示例:

AnotherFragment 另一个片段

Create new Fragment instance for the myFragment like 为myFragment创建新的Fragment实例,例如

myFragment = new MyFragment();

And use .replace method to change the fragment. 并使用.replace方法更改片段。

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

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