Reputation: 35
i use Android Studio Version 3.6 with API 29 and i has problem in the recycler View Adapter in this code
@NonNull
@Override
public MyView onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view= LayoutInflater.from(getContext()).inflate(R.layout.exampel,parent,false);
return new MyView(view);
}
why i cant use the getContext()??
Upvotes: 0
Views: 144
Reputation: 131
RecyclerView.Adapter does not have a getContext() you need to use the parent context.
@NonNull
@Override
public MyView onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.exampel,parent,false);
return new MyView(view);
}
Upvotes: 0
Reputation: 4756
Because RecyclerView.Adapter
doesn't have a getContext()
method.
You can use parent.getContext()
instead
Upvotes: 1