AndroidFragment

Summary: Author: 张亚飞 | 阅读时间: 1 minute read | Published: 2015-05-26
Filed under Categories: LinuxTags: Note,

AndroidFragment 相关


Fragment 结合 DrawerLayout


Fragment 旋屏及配置改变 运行数据保存问题


在 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

Cor-Ethan, the beverage → www.iirii.com