【发布时间】:2014-08-21 15:38:38
【问题描述】:
我有一个应用程序,它包含 3 个片段作为基于初始活动的选项卡。
中间选项卡有一个保存日期的按钮。这只是一个将所选日期添加到本地首选项的日期选择器。
设置此日期后,当我滑动到左侧片段选项卡时,我想查看该日期。
在片段生命周期或其他方面我需要更改/考虑什么,以便当我在中间片段选项卡中更新此值时,我可以立即在最左侧的片段选项卡上获取、使用和显示数据。
目前它仅在我关闭应用程序时才有效。重新创建片段似乎没有得到更新的日期值。我已经尝试重新获取 onCreate、onStart、onResume、instantiateItem 等中的数据。
标签代码基于这个简单的官方 Google 示例项目:https://developer.android.com/samples/SlidingTabsColors/index.html
我还没有包含任何代码,因为这个概念可以很容易地从示例项目中复制/理解。
ArticleFragment newFragment = new ArticleFragment();
Bundle args = new Bundle();
args.putInt(ArticleFragment.ARG_POSITION, position);
newFragment.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack so the user can navigate back
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
【问题讨论】:
标签: android android-fragments android-tabs