android.support.v7.widget.RecyclerView$ViewHolder的类文件

问题描述 投票:0回答:3

我已更新我的应用程序以使用 androidx,从那时起我收到此错误:

class file for android.support.v7.widget.RecyclerView$ViewHolder

这是我的模块 buidle.gradle:

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'io.realm:android-adapters:3.1.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.recyclerview:recyclerview-selection:1.1.0'
implementation 'com.google.android.gms:play-services-ads:19.8.0'
implementation 'com.prolificinteractive:material-calendarview:1.4.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}

我已经删除了

all reference to android.support.v7.widget.RecyclerView
。我有另一个应用程序使用相同的依赖项,一切正常。

Andapter Studio 在以下线上抱怨:

public class MyAdapter extends RealmRecyclerViewAdapter<MyModel, MyViewHolder> {

与:

Type parameter MyViewHolder is not with its bound. Should extend android.support.v7.widget.RecyclerView.ViewHolder

android android-recyclerview realm
3个回答
2
投票

更新

io.realm:android-adapters
依赖项:

implementation 'io.realm:android-adapters:4.0.0'

0
投票

我能够通过在 app/build.gradle 中实现以下依赖项来解决同样的问题

implementation 'com.android.support:appcompat-v7:28.0.0'

0
投票

如果您创建了类似这样的 MyViewHolder 类:

public static class MyViewHolder extends RecyclerView.ViewHolder{

    View mView;


    public MyViewHolder(@NonNull View itemView) {
        super(itemView);
        mView=itemView;
    }

    private void setType(String type){
        TextView mType=mView.findViewById(R.id.type_txt_income);
        mType.setText(type);
    }
    private void setNote(String note){
        TextView mNote=mView.findViewById(R.id.note_txt_income);
        mNote.setText(note);
    }
    private void setDate(String date){
        TextView mDate=mView.findViewById(R.id.date_txt_income);
        mDate.setText(date);
    }
    private void setAmount(int amount){
        TextView mAmount=mView.findViewById(R.id.amount_txt_income);
        String stamount=String.valueOf(amount);
        mAmount.setText(stamount);
    }
}

那么,我会建议你这样改,或者你可以这样尝试:

public class MyViewHolder extends android.support.v7.widget.RecyclerView.ViewHolder {

    View mView;

    public MyViewHolder(@android.support.annotation.NonNull View itemView) {
        super(itemView);
        mView = itemView;
    }

    private void setType(String type) {
        TextView mType = mView.findViewById(R.id.type_txt_income);
        mType.setText(type);
    }

    private void setNote(String note) {
        TextView mNote = mView.findViewById(R.id.note_txt_income);
        mNote.setText(note);
    }

    private void setDate(String date) {
        TextView mDate = mView.findViewById(R.id.date_txt_income);
        mDate.setText(date);
    }

    private void setAmount(int amount) {
        TextView mAmount = mView.findViewById(R.id.amount_txt_income);
        String stamount = String.valueOf(amount);
        mAmount.setText(stamount);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.