android.app.Fragment与android.support.v4.app.Fragment不一致
在看法中用到的Fragment在类型转换的时候非常easy出现这样的问题:
对照代码:
class MyFragmentPagerAdapter extends FragmentPagerAdapter{
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
// TODO Auto-generated constructor stub
}
@Override
public Fragment getItem(int arg0) {
// TODO Auto-generated method stub
Fragment ft = null;
switch (arg0) {
case 0:
ft = new MainPaperFragment();
break;
default:
break;
}
return ft;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return MainActivity.this.tabTitle.length;
}
}
与:
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.kuhua.R; public class MainPaperFragment extends Fragment { @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View MainPaperFragmentView = inflater.inflate(R.layout.mainpaperfragmentview, container,false);
return MainPaperFragmentView;
} @Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
}
}
在上述fragment中 Fragment ft = new MainPaperFragment()本质上没有错,是一种多态,可是一般开发中总easy报错;原因当然在自己,我们在用Fragment的时候大体上知道是导入的import android.support.v4.app.Fragment可是在自己定义Fragment的时候easy直接用了系统的import android.app.Fragment这样就造成了所使用的api不一致。解决办法就是记得所有都用导入的import android.support.v4.app.Fragment就ok了。
android.app.Fragment与android.support.v4.app.Fragment不一致的更多相关文章
- 在布局中使用android.support.v4.app.Fragment的注意事项
1.Activity必须继承android.support.v4.app.FragmentActivity 2.fragment标签的name属性必须是完全限定包名,如下: <LinearLay ...
- android.support.v4.app.Fragment和android.app.Fragment区别
1.最低支持版本不同 android.app.Fragment 兼容的最低版本是android:minSdkVersion="11" 即3.0版 android.support.v ...
- Attempt to write to field 'android.support.v4.app.FragmentManagerImpl android.support.v4.app.Fragment.mFragmentManager' on a null object reference
E/AndroidRuntime﹕ FATAL EXCEPTION: mainProcess: org.example.magnusluca.drawertestapp, PID: 3624java. ...
- Android fragment切换后onresume时报 Attempt to write to field 'int android.support.v4.app.Fragment.mNextAnim'
动态加载fragment以后,调用了remove方法移除Fragment,在返回来的时候报 Attempt to write to field 'int android.support.v4.app. ...
- [转]android.support.v4.app.Fragment和android.app.Fragment区别
1.最低支持版本不同 android.app.Fragment 兼容的最低版本是android:minSdkVersion="11" 即3.0版 android.support ...
- android.support.v4.app.Fragment vs android.app.Fragment 的区别
android.support.v4.app.Fragment vs android.app.Fragment 的区别 我开过平板相关应用,用了Fragment来处理.后来重新开发另外一个应用,直接引 ...
- android.app.FragmentManager 与 android.support.v4.app.FragmentManager带来的若干Error
Fragment是activity的界面中的一部分或一种行为.你能够把多个Fragment们组合到一个activity中来创建一个多面界面而且你能够在多个activity中重用一个Fragment.你 ...
- app:transformClassesWithJarMergingForDebug uplicate entry: android/support/v4/app/BackStackState$1.class
.Execution failed for task ':app:transformClassesWithJarMergingForDebug'.> com.android.build.api. ...
- 安卓开发错误:The type android.support.v4.app.TaskStackBuilder$SupportParentable cannot be resolved.
今天在使用低版本下的ActionBar,在继承ActionBarActivity时报了"The type Android.support.v4.app.TaskStackBuilder$Su ...
随机推荐
- hdfs深入:09、获取分布式文件系统客户端的几种方式
FileSystem是一个抽象类:获取一个抽象类有两种方式:第一种:看这个抽象类有没有提供什么方法返回他本身第二种:找子类 具体代码如下: /** * 通过url注册的方式访问hdfs,了解,不会用到 ...
- UTF-8,UTF-16
UTF是 Unicode Translation Format,即把Unicode转做某种格式的意思. 在Unicode基本多文种平面定义的字符(无论是拉丁字母.汉字或其他文字或符号),一律使用2字节 ...
- 爬虫项目 之(一) --- urllib 和 正则re
from urllib import request,parse from time import sleep import re # 1.[数据的获取] # 封装一个函数,用于将url转化成一个请求 ...
- 笔记——python语言规范
Lint 对你的代码运行pylint 定义: pylint是一个在Python源代码中查找bug的工具. 对于C和C++这样的不那么动态的(译者注: 原文是less dynamic)语言, 这些bug ...
- 笔记——python风格规范
分号 不要在行尾加分号, 也不要用分号将两条命令放在同一行. 行长度 每行不超过80个字符 例外: 长的导入模块语句 注释里的URL 不要使用反斜杠连接行. Python会将 圆括号, 中括号和花括号 ...
- Cadence中画原理图的时候器件标号与黄色的参数不同的解决办法
方法是Accessories->Transfer Occ. Prop to Instance->Push Occ. Prop into Instance 将黄色的参数同样应用到源参数. 版 ...
- Git--使用须知123
详细的篇幅以后补充 安装篇: 设置篇: 由于我们大多数是windows程序员,那么,在使用git的过程前需要做一些设置项. 1.换行符自动转换. 查看:git config --global --li ...
- Spring框架中 配置c3p0连接池
开发准备: 1.导入jar包: ioc基本jar jdbcTemplate基本jar c3p0基本jar 别忘了mysql数据库驱动jar 原始程序代码:不使用配置文件方式(IOC)生成访问数据库对象 ...
- 学习使用windows下类似iptables的防火墙软件
项目地址:http://wipfw.sourceforge.net一.下载地址:http://sourceforge.net/projects/wipfw/files/安装:解压软件包后执行insta ...
- 【bzoj2152】聪聪可可 点分治
[bzoj2152]聪聪可可 2014年9月7日3,5472 Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是 ...