我似乎无法为我的recyclerview实现/扩展OnScrollistener以了解recyclelerview何时触及底部
public class UpcomingFragment extends Fragment
如果符合以下条件我如何实施:
implements RecyclerView.OnScrollListener
和
implements OnScrollListener
给我一个“预期接口”错误
我的构建gradle模块:
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "company.com.movieapp"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
构建成绩项目
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
答案 0 :(得分:4)
https://developer.android.com/reference/android/support/v7/widget/RecyclerView.OnScrollListener.html
RecyclerView.OnScrollListener
是abstract
。
private final RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(final RecyclerView recyclerView, final int newState) {
// code
}
@Override
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
// code
}
};
RecyclerView
:recyclerView.addOnScrollListener(onScrollListener);
答案 1 :(得分:0)
private final RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(final RecyclerView recyclerView, final int newState) {
// code
}
@Override
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
// code
}
};
然后将onScrollListener添加到方法addOnScrollListener中
recyclerView.addOnScrollListener(onScrollListener);