第一步导入jar包
在app目录下的build.gradle文件中添加
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.22'
implementation 'com.android.support:recyclerview-v7:27.1.1'
再到工程目录下的build.gradle文件中添加
buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这样在项目中就能使用Recyclerview和万能适配器BaseQuickAdapter了
第二步 当然是新建布局加入Recyclerview了,这里我加入了Google官方的下拉刷新控件SwipeRefreshLayout
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
初始化控件设置各种属性
/**
* 初