android - 为什么我的 RecyclerVIewSwipeDecorator 库没有被导入?
问题描述
我正在尝试在我的应用程序上实现以下库: https ://github.com/xabaras/RecyclerViewSwipeDecorator
我已经在 gradle 中同步了它,但我无法导入它以供使用。
这是我的毕业生:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.mylist"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
//For view binding
buildFeatures {
viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
//CardView
implementation "androidx.cardview:cardview:1.0.0"
//Recycler View Swipe Decorator
implementation 'it.xabaras.android:recyclerview-swipedecorator:1.2.3'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.firebase:firebase-firestore:23.0.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
其他等级:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
classpath 'com.google.gms:google-services:4.3.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
//jcenter() // Warning: this repository is going to shut down soon
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是我尝试使用它的地方:
package com.example.mylist;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Color;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import com.example.mylist.Adapters.TaskAdapter;
//this shows error on xabaras
import it.xabaras.android.recyclerview.swipedecorator.RecyclerViewSwipeDecorator;
public class TouchHelper extends ItemTouchHelper.SimpleCallback {
private TaskAdapter taskAdapter;
public TouchHelper(TaskAdapter taskAdapter) {
super(0 , ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT); //for dragging and swiping
this.taskAdapter = taskAdapter;
}
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
final int position = viewHolder.getAdapterPosition();
if (direction == ItemTouchHelper.RIGHT){
AlertDialog.Builder builder = new AlertDialog.Builder(taskAdapter.getContext());
builder.setMessage("Are you sure you want to delete this task?")
.setTitle("Delete Task")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
taskAdapter.deleteTask(position);
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
taskAdapter.notifyItemChanged(position);
}
});
AlertDialog dialog = builder.create();
dialog.show();
}else{
taskAdapter.editTask(position);
}
}
@Override
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
//can't use these
new RecyclerViewSwipeDecorator.Builder(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
.addSwipeRightActionIcon(R.drawable.ic_baseline_delete_24)
.addSwipeRightBackgroundColor(Color.RED)
.addSwipeLeftActionIcon(R.drawable.ic_baseline_edit_24)
.addSwipeLeftBackgroundColor(ContextCompat.getColor(taskAdapter.getContext() , R.color.edit_color))
.create()
.decorate();
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
}
我曾尝试在 gradle 中单独实现 RecyclerView,但没有奏效。此外,我在所有活动中都使用 ViewBinding,因此这可能是一个影响因素。
请帮帮我。
解决方案
从他们使用的库中,jcenter()
来自基本构建 gradle 文件。因此,请确保您已从基本构建 gradle 添加了存储库。
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
...
}
}
allprojects {
repositories {
jcenter()
google()
}
}
并且jcenter()
已经被弃用并检查mavenCentral()
推荐阅读
- laravel - 在 Backpack CRUD 视图中下载时路径错误
- scheme - 如何使用 DrRacket 遵循简单方案书
- java - 如何禁用 WebView 中的链接、页面和引用?
- c++ - 我应该将派生类析构函数标记为虚拟/覆盖吗?
- java - Java ScheduledExecutorService 以 100% 运行一个 CPU 内核(但不执行任务)
- swift - 在延迟块中传播异常的正确方法
- javascript - 只需指定字符的开始和结束索引,就可以用标签包围文本范围
- r - Barplot dplyr 汇总值
- javascript - 如何在按钮单击事件 ASP 后调用 javascript 函数
- android - gradle 文件中的版本冲突