How to import RecyclerView for Android L-preview

前端 未结 22 1547
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 14:55

Trying to use the new RecyclerView from the support library. I downloaded the 20 update for the support library using the SDK manager.

I\'ve added the jar file to th

相关标签:
22条回答
  • 2020-12-02 15:37

    Figured it out.

    You'll have to add the following gradle dependency :

    compile 'com.android.support:recyclerview-v7:+'
    

    another issue I had compiling was the compileSdkVersion. Apparently you'll have to compile it against android-L

    Your build.gradle file should look something like this:

    apply plugin: 'android'
    android {
        compileSdkVersion 'android-L'
        buildToolsVersion '19.1.0'
        [...]
    }
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:recyclerview-v7:+'
    }
    
    0 讨论(0)
  • 2020-12-02 15:37

    -Go to the DESIGN part in activity_main.xml -In the drag drop pallet select appCompactivity -In appCompactivity Select RecyclerView -On Selection a dialog shall appear click OK -Your project app:gradle will automatically get updated

    0 讨论(0)
  • 2020-12-02 15:37
    import android.support.v7.widget.RecyclerView;
    

    In Android Studio, importing is not as intuitive as one would hope. Try importing this bit and see how it helps!

    0 讨论(0)
  • 2020-12-02 15:38
    implementation 'com.android.support:appcompat-v7:28.0.0'
    
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    

    Above works for me in build.gradle file

    0 讨论(0)
  • 2020-12-02 15:42

    Just an update:

    'compile' is obsolete now; it has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018 I believe. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

    Also all com.android.support libraries must use the exact same version specification; in addition, support libraries such as appcompat-v7 and recyclerview-v7 should not use a different version than the compileSdkVersion.

    0 讨论(0)
  • 2020-12-02 15:44

    A great way to import the RecyclerView into your project is the RecyclerViewLib. This is an open source library which pulled out the RecyclerView to make it safe and easy implement. You can read the author's blog post here.

    Add the following line as a gradle dependency in your code:

    dependencies {
        compile 'com.twotoasters.RecyclerViewLib:library:1.0.+@aar'
    }
    

    More info for how to bring in gradle dependencies:

    Bosnia you're right about that being annoying. Gradle may seem complicated but it is extremely powerful and flexible. Everything is done in the language groovy and learning the gradle system is learning another language just so you can build your Android app. It hurts now, but in the long run you'll love it.

    Check out the build.gradle for the same app. https://github.com/twotoasters/RecyclerViewLib/blob/master/sample/build.gradle Where it does the following is where it brings the lib into the module (aka the sample app)

    compile (project (':library')) {
        exclude group: 'com.android.support', module: 'support-v4' 
    }
    

    Pay attention to the location of this file. This is not the top level build.gradle

    Because the lib source is in the same project it is able to do this with the simple ':library'. The exclude tells the lib to use the sample app's support v4. That isn't necessary but is a good idea. You don't have or want to have the lib's source in your project, so you have to point to the internet for it. In your module's/app's build.gradle you would put that line from the beginning of this answer in the same location. Or, if following the samples example, you could replace ':library' with ' com.twotoasters.RecyclerViewLib:library:1.0.+@aar ' and use the excludes.

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