Reputation: 33
Im new in android development... why im getting this error:- "findviewbyid cannot resolve method" while using findviewbyid in viewholder method... Thanks in advance ! I want to add image from my drawable, im using recyclerview for this purpose... here's the code:-
public class ViewHolder extends RecyclerView.ViewHolder{
TextView stateName;
ImageView stateImage;
public ViewHolder(@NonNull View itemView) {
super(itemView);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(v.getContext(),Details.class);
i.putExtra("titleOfState",stitles[getAdapterPosition()]);
i.putExtra("contentOfState",scontents[getAdapterPosition()]);
v.getContext().startActivity(i);
}
});
stateName=itemView.findViewById(R.id.stateName);
stateImage=(ImageView)findViewById(R.id.imageView);
}
}
Upvotes: 0
Views: 314
Reputation: 145
You've just missed refering to itemView
, replace your stateImage line with this line, and it should work fine.
stateImage = itemView.findViewById(R.id.imageView);
Upvotes: 0
Reputation: 4007
findViewById()
is a method of View
object and not ViewHolder
.
Just call it on itemView
Upvotes: 2