Search code examples
androidandroid-fragmentsandroid-recyclerviewandroid-context

getContext() not recognised


In getContext() its showing "Non-static method 'getContext()' cannot be referenced from a static context" how to solve it,or what should i call instead of it.

public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.ViewHolder > {

private List<CategoryModel> CategoryModelList;

public CategoryAdapter(List<CategoryModel> categoryModelList) {
    CategoryModelList = categoryModelList;
}

@NonNull
@Override
public CategoryAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
    View view = LayoutInflater.from(ViewGroup.getContext()).Inflate(R.layout.category_item,viewGroup,false);
    return null;
}

@Override
public void onBindViewHolder(@NonNull CategoryAdapter.ViewHolder holder, int position) {

}

@Override
public int getItemCount() {
    return 0;
}

Solution

  • You are using ViewGroup but it should be viewGroup