AndroidFragment
Summary: Author: 张亚飞 | Read Time: 1 minute read | Published: 2015-05-26
Filed under
—
Categories:
Linux
—
Tags:
Note,
AndroidFragment 相关
Fragment 结合 DrawerLayout
Fragment 旋屏及配置改变 运行数据保存问题
- [半分钟读完]Android中保存和恢复Fragment状态的最好方法](http://www.race604.com/fast-note-keep-android-fragment-state/)
- 保存和恢复 Android Fragment 的状态
- 用Fragment解决屏幕旋转(状态发生变化)状态不能保持的问题
- The Real Best Practices to Save/Restore Activity’s and Fragment’s state. (StatedFragment is now deprecated)
- onSaveInstanceState和onRestoreInstanceState在Activity生命周期中的位置
在 Fragment 中使用 ViewPager 加载子 Fragment 一定要使用 getChildFragmentManager() 而不应该是 getSupportFragmentManager(),否则会出现切换后不显示内容
Fragment tags are not automatically specified. You have to assign them yourself. There are several places to do it depending on how you attach fragment: in the XML or dynamically.
一. If it’s define in XML then you can set it like this:
<fragment android:name="com.example.news.ArticleListFragment"
android:id="@+id/list"
android:tag="your_tag"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
二. If you add fragment dynamically then you can do it like this:
ExampleFragment fragment = new ExampleFragment();
fragmentTransaction.add(R.id.fragment_container, fragment, "your_tag");
fragmentTransaction.commit();
两种方式均设定相同的Tag “your_tag”.
Comments