您的位置:首页 > 移动开发 > Android开发

android-Fragment

2015-11-26 21:11 429 查看
Fragment的类型有:DialogFragmentListFragmentPreferenceFragment

不保存当前的Fragment时,使用Fragment.commitAllowingStateLoss()方法


For example, if a news application has two fragments in an activity—one
to show a list of articles (fragment A) and another to display an article (fragment B)—then fragment A must tell the activity when a list item is selected so that it can tell fragment B to display the article. In this case, the OnArticleSelectedListener
interface
is declared inside fragment A:

Fragment A通过Activity传输数据到Fragment B,实现机制:Fragment
A定义一个interface,Activity去实现接口,并将返回通知给Fragment B。


将Activity的数据传给Fragment时,可以使用Bundle.


Also
like an activity, you can retain the state of a fragment using a Bundle
,
in case the activity's process is killed and you need to restore the fragment state when the activity is recreated. You can save the state during the fragment's
onSaveInstanceState()
callback
and restore it during either
onCreate()
,
onCreateView()
,
or
onActivityCreated()
.

横竖屏切换时,Activity状态的保存。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: