我想在我的项目中使用FirebaseRecyclerAdapter,并且在以前的项目中使用了此代码段,它工作正常,但现在不再起作用,新版本的FirebaseUi是否有无法更新的更新?现在允许我重用此代码吗?
我在项目中尝试过
@Override
protected void onStart(){
super.onStart();
FirebaseRecyclerAdapter<Model,ViewHolder> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter<Model, ViewHolder>(
Model.class,
R.layout.row,
ViewHolder.class,
mRef
) {
@Override
protected void onBindViewHolder( ViewHolder holder, int position, Model model) {
holder.setDetails(getApplicationContext(),model.getTitel(),model.getImages(),model.getDesc());
}
};
mRecyclerView.setAdapter(firebaseRecyclerAdapter);
}
并且Android Studio出现错误,提示您必须实现onCreateViewHolder,onBindViewHolder方法。
ViewHolder类
package com.example.varunwadhwa.myapplication;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
public class ViewHolder extends RecyclerView.ViewHolder {
View mView;
public ViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setDetails(Context ctx,String title, String desc , String image ){
TextView mTitleView = mView.findViewById(R.id.rTitleTv);
TextView mDtailTv = mView.findViewById(R.id.rDescTv);
TextView mImageTv = mView.findViewById(R.id.rImageView);
mTitleView.setText(title);
mDtailTv.setText(desc);
Picasso.get().load(image).into((Target) mImageTv);
}
}
我使用此依赖项
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-database:16.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.firebaseui:firebase-ui-database:4.0.1'
implementation 'com.squareup.picasso:picasso:2.71828'
}