用FragmentActivity实现点击跳转Fragment效果(未完)
2015-12-09 22:12
288 查看
因为TabHost已经不推荐使用了,所以现在一般都用FragmentTabHost,但是因为Fragment在3.0才出现,所以为了解决低版本兼容问题。我们要引入android.support.v4.app包!注意:当你导入跟FragmentTabHost相关包时,都要导成android.support.v4.app包!不然会报错不能兼容。
简单说一下v4兼容包,其算是android最低等级的支持包。其中它的支持包主要为:
1.Fragment
英文:
class overview:
Static library support version of the framework’s Fragment. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework’s implementation. See the framework Fragment documentation for a class overview.
The main differences when using this support version instead of the framework version are:
Your activity must extend FragmentActivity
You must call getSupportFragmentManager() to get the FragmentManager
主要方法:
1.final FragmentActivity getActivity()
Return the FragmentActivity this fragment is currently associated with.
2.final FragmentManager getChildFragmentManager()
Return a private FragmentManager for placing and managing Fragments inside of this Fragment.
3.final FragmentManager getFragmentManager()
Return the FragmentManager for interacting with fragments associated with this fragment’s activity.(与其他fragment通信)
4.final Fragment getTargetFragment()
Return the target fragment set by setTargetFragment(Fragment, int).
5.final int getTargetRequestCode()
Return the target request code set by setTargetFragment(Fragment, int).
6.View getView()
Get the root view for the fragment’s layout (the one returned by onCreateView(LayoutInflater, ViewGroup, Bundle)), if provided.
7.static Fragment instantiate(Context context, String fname, Bundle args)
Create a new instance of a Fragment with the given class name.
8.void onActivityCreated(Bundle savedInstanceState)
Called when the fragment’s activity has been created and this fragment’s view hierarchy instantiated.
构造函数:
对于构造函数来说,强烈建议不要重载带有参数的构造函数,因为Fragment重新实例化并不会调用带参构造函数。对于需要参数的情况,应该在构造fragment后立即书写setArguments(Bundle),这个Bundle会跨越fragment的销毁和重生,通过getArguments()来获得参数、
简单说一下v4兼容包,其算是android最低等级的支持包。其中它的支持包主要为:
1.Fragment
英文:
class overview:
Static library support version of the framework’s Fragment. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework’s implementation. See the framework Fragment documentation for a class overview.
The main differences when using this support version instead of the framework version are:
Your activity must extend FragmentActivity
You must call getSupportFragmentManager() to get the FragmentManager
主要方法:
1.final FragmentActivity getActivity()
Return the FragmentActivity this fragment is currently associated with.
2.final FragmentManager getChildFragmentManager()
Return a private FragmentManager for placing and managing Fragments inside of this Fragment.
3.final FragmentManager getFragmentManager()
Return the FragmentManager for interacting with fragments associated with this fragment’s activity.(与其他fragment通信)
4.final Fragment getTargetFragment()
Return the target fragment set by setTargetFragment(Fragment, int).
5.final int getTargetRequestCode()
Return the target request code set by setTargetFragment(Fragment, int).
6.View getView()
Get the root view for the fragment’s layout (the one returned by onCreateView(LayoutInflater, ViewGroup, Bundle)), if provided.
7.static Fragment instantiate(Context context, String fname, Bundle args)
Create a new instance of a Fragment with the given class name.
8.void onActivityCreated(Bundle savedInstanceState)
Called when the fragment’s activity has been created and this fragment’s view hierarchy instantiated.
构造函数:
对于构造函数来说,强烈建议不要重载带有参数的构造函数,因为Fragment重新实例化并不会调用带参构造函数。对于需要参数的情况,应该在构造fragment后立即书写setArguments(Bundle),这个Bundle会跨越fragment的销毁和重生,通过getArguments()来获得参数、
相关文章推荐
- mfc 模仿键盘按键向银行密码控件输入密码
- ArrayList、Vector、LinkedList的区别及其优缺点?
- 如何使用vs对程序进行打包?怎么通过注册表获取安装路径?
- 自我简介
- 实验四
- logstash 输出到elasticsearch 自动建立index
- 【iCore3 双核心板】例程十:RTC实时时钟实验——显示日期和时间
- 动态规划 - 最长公共子序列(LCS)
- 变量,常量,引用类型,值类型,枚举类型, 值类型和引用类型的简单区别,类型转换,装箱与拆箱
- tableView的重用机制
- iOS 推送 通知 测试
- windows下安装配置apache、mysql、php
- Android studio安装和一些快捷键
- 实验五
- 07-定时器之雪花
- 一天一个数据结构之HashMap
- nfs服务检测与自动恢复
- 10018---HttpClient 基本使用
- python 与hadoop之pyhdfs的使用
- OC - 第八章(二) KVC