androidandroid-studioandroid-recyclerviewadapterandroid-studio-3.6

Problem in RecyclerView Adapter AndroidStudio


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()??


Solution

  • Because RecyclerView.Adapter doesn't have a getContext() method. You can use parent.getContext() instead