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 ...
随机推荐
- oracle数据库使用hint来让模糊查询走索引
在没有创建数据直方图之前,查询优化器是cbo,可能不会选择代价最低(效率最高)的方式查询. 先创建表 --日语假名表 CREATE TABLE JAPANESE_SOUNDMARK ( ID INTE ...
- nexus 搭建 maven 私服
nexus 搭建 maven 私服 本机环境 Win 8 JDK 7 Maven 3.2 Nexus 2.11 版本选择 http://www.sonatype.org/nexus/archivedn ...
- kafka可视化客户端工具(Kafka Tool)安装
参考:https://www.cnblogs.com/frankdeng/p/9452982.html
- PermGen space OOM 记录
前些天线上除出了个OOM问题,今天闲下来记录下: OOM的提示信息是-PermGen space,说明问题出在方法区,方法区存的是什么东西?:类的加载信息.常量.静态变量. 按照方法区的定义:类加载的 ...
- oracle的备份方式
一.完全备份 exp 用户/密码@库名 file=存储位置 二.RMAN https://www.cnblogs.com/Latiny/p/6920428.html RMAN在数据库服务器的帮助下实现 ...
- add list of symbols in latex
* add list of symbols -- latex 1. createa new tex file named "toc.tex' with the following conte ...
- 程序包javax.servlet.http不存在
在maven test项目时,出现错误: java:[7,26] 程序包javax.servlet.http不存在 原因:pom.xml中未引入javax.servlert-api相关的包 <d ...
- Codeforce 741B Arpa's weak amphitheater and Mehrdad's valuable Hoses(并查集&分组背包)
题意: 给定n个价值为b 花费为w的物品, 然后某些物品是属于同一个组的, 给定一个花费限制V, 求在小于等于V的情况下取得到的价值最大为多少,能对于同一个组的物品,要么全取,要么只取一个. 分析: ...
- xtu read problem training 4 B - Multiplication Puzzle
Multiplication Puzzle Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. O ...
- [luoguP1010] 幂次方 ^(* ̄(oo) ̄)^
传送门 递归.. 代码 #include <cstdio> int n; int bit[15]; inline void solve(int x) { int i, f = 0; if( ...