zoukankan      html  css  js  c++  java
  • XXXfragment that is not a fragment错误,fragment认不出来

    要注意的是fragment事实上是有两个版本号的,一个是

    import android.support.v4.app.Fragment;

    另外一个是

    import android.app.Fragment;

    这两个版本号的fragment是不会兼容的。也就是说要不就全用fragment,要不就全用v4 fragment。不能混搭着用。

    在这里我强烈建议刚開始学习的人用第二个,也就是简单的fragment,接下来我说说两者的差别大家就知道为什么了。


    1.最低支持版本号不同

    android.app.Fragment 兼容的最低版本号是android:minSdkVersion="11" 即3.0版

    android.support.v4.app.Fragment 兼容的最低版本号是android:minSdkVersion="4" 即1.6版

     

    2.须要导jar包

    fragment android.support.v4.app.Fragment 须要引入包android-support-v4.jar


    3.在Activity中取的方法不同

    android.app.Fragment使用 (ListFragment)getFragmentManager().findFragmentById(R.id.userList)  获得  ,继承Activity(这个只须要继承自最简单的activity)


    android.support.v4.app.Fragment使用 (ListFragment)getSupportFragmentManager().findFragmentById(R.id.userList) 获得 ,须要继承android.support.v4.app.FragmentActivity


    4.我感觉最重要的,是XML标签的使用


    android.app.Fragment能够使用<fragment>标签的,这点非常重要。假设是用android.support.v4.app.Fragment的话,是不能是用<fragment>标签的,会抛出android.view.InflateException: Binary XML file line #7: Error inflating class fragment异常。

    由于这个标签的使用还是比較简单的,所以还是比較倾向前者




  • 相关阅读:
    软件测试 -- alpha测试和beta测试的区别
    软件测试--各种测试的概念
    linux 安装memcached
    Visual Studio 2013 Preview
    基于HAL库STM32的FSMC驱动8位TFTLCD屏
    LM358电压跟随器
    广耦的应用
    MOS管的开关作用
    三极管的开关作用
    STM32的BOOT0 BOOT1的选择
  • 原文地址:https://www.cnblogs.com/clnchanpin/p/6971643.html
Copyright © 2011-2022 走看看