我正在尝试使用“回收者”视图来检索我的Firebase数据。但是,我遇到以下错误:
error: constructor FirebaseRecyclerAdapter in class FirebaseRecyclerAdapter<T,VH> cannot be applied to given types;
required: FirebaseRecyclerOptions<SearchResult>
found: Class<SearchResult>,int,Class<SnakeViewHolder>,DatabaseReference
reason: actual and formal argument lists differ in length
where T,VH are type-variables:
T extends Object declared in class FirebaseRecyclerAdapter
VH extends ViewHolder declared in class FirebaseRecyclerAdapter
以下是我项目中的相关代码:
private void snakeSearch(String searchtext) {
Toast.makeText(Search_Activity.this,"Strated Search",Toast.LENGTH_LONG).show();
Query firebaseSearchQuery= mSnakeReference.orderByChild("name").startAt(searchtext).endAt(searchtext+"\uf8ff");
FirebaseRecyclerAdapter<SearchResult,SnakeViewHolder > firebaseRecyclerAdapter=new FirebaseRecyclerAdapter<SearchResult, SnakeViewHolder>(
SearchResult.class,
R.layout.searchresult_list,
SnakeViewHolder.class,
mSnakeReference
)
{
@Override
protected void onBindViewHolder(@NonNull SnakeViewHolder holder, int position, @NonNull SearchResult model) {
holder.setDetails(model.getSnakename(),model.getVenoumousness());
}
@NonNull
@Override
public SnakeViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
return null;
}
};
mResultList.setAdapter(firebaseRecyclerAdapter);
}
// view holder class
public static class SnakeViewHolder extends RecyclerView.ViewHolder{
View mview;
public SnakeViewHolder(@NonNull View itemView) {
super(itemView);
mview=itemView;
}
public void setDetails( String snakename, String venoumousness){
TextView Snakename=(TextView) mview.findViewById(R.id.id_SnakeName);
TextView Venomusness=(TextView)mview.findViewById(R.id.id_VEnoumoses);
Snakename.setText(snakename);
Venomusness.setText(venoumousness);
}
}
}
红线出现在firebaserecyclerAdapter内,我已在其中传递了类,布局,视图持有人和数据库引用。