Reputation: 407
I am trying to build a custom recyclerView adapter but it's show error in onCreateViewHolder.
How to instantiate abstract class ?
What's the problem in my code ?
I have checked other answers too all said that your name must be duplicate or you must have imported wrong class but none of them helped.
A suggestion would be great considering me in a learning phase.
public class RegisteredRecyclerAdapter extends RecyclerView.Adapter<RegisteredRecyclerAdapter.ViewHolder> {
public Context context;
private FirebaseAuth firebaseAuth;
private FirebaseFirestore firebaseFirestore;
@NonNull
@Override
public RegisteredRecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.registered_item_listview,parent,false);
context = parent.getContext();
firebaseFirestore = FirebaseFirestore.getInstance();
firebaseAuth = FirebaseAuth.getInstance();
return new RecyclerView.ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull RegisteredRecyclerAdapter.ViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return 0;
}
public class ViewHolder extends RecyclerView.ViewHolder{
public ViewHolder(@NonNull View itemView) {
super(itemView);
}
}
}
Upvotes: 0
Views: 5486
Reputation: 3100
as @Amin said you are trying invalid return in onCreateViewHolder() try below
@NonNull
@Override
public RegisteredRecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.registered_item_listview,parent,false);
context = parent.getContext();
firebaseFirestore = FirebaseFirestore.getInstance();
firebaseAuth = FirebaseAuth.getInstance();
return new RegisteredRecyclerAdapter.ViewHolder(view); //change here
}
Upvotes: 0
Reputation: 1290
You are trying to create an instance of RecycleView.ViewHolder
not RegisteredRecyclerAdapter.ViewHolder
in onCreateViewHolder()
method. Since RecycleView.ViewHolder
is an abstract
class, you are getting this error.
Upvotes: 6