Custom Layout Inflation with Fragments in Robolectric not working

后端 未结 4 1148
刺人心
刺人心 2021-01-12 10:34

When inflating a layout in a Fragment, with the LayoutInflater, i am getting this exception:

 ./res/layout/locations_list.xml line #-1 (sorry, not yet implem         


        
相关标签:
4条回答
  • 2021-01-12 11:04

    I figured it out, and if you got stock to such an situation just look for your IDs in the XML, even though

     android:id="@+id/android:list"
    

    is often seen in some example code it must be:

     android:id="@android:id/list"
    
    0 讨论(0)
  • 2021-01-12 11:18

    In my case I got this problem when I had this in my app:

        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>support-v4</artifactId>
            <version>r13</version>
        </dependency>
    

    but this in my unittest project:

        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>support-v4</artifactId>
            <version>r7</version>
        </dependency>
    

    The older version of the support library I used in the tests didn't contain the class I was trying to use (android.support.v4.widget.DrawerLayout).

    0 讨论(0)
  • 2021-01-12 11:21

    In my case, my FragmentActivity XML was inflating a Fragment that was expecting a Bundle. I swapped the XML for a FrameLayout holder and added the fragment with the proper bundle in the activity.

    0 讨论(0)
  • 2021-01-12 11:25

    The last version of Robolectric (3.0-Snapshot) has some problems with customized views.

    To fix that, do the follow:

    1. In the module app where your code is, create a file called project.properties, at the same level as AndroidManifest.xml
    2. Fill the content with reference to the class folder of build. e.g. for StaggeredGridView:

    android.library.reference.1=../../build/intermediates/exploded-aar/com.etsy.android.grid/library/1.0.5

    Here you must check three things:

    • There should be one line per reference
    • Each reference has one number (1, 2, 3), which should be increase by one each time
    • The version number folder at the end must match with the version number in your build.gradle file.

    You have an example of project working here: https://github.com/jiahaoliuliu/RobolectricSample/blob/master/app/src/main/project.properties

    0 讨论(0)
提交回复
热议问题