简体   繁体   English

RecyclerView Adapter AndroidStudio 中的问题

[英]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我使用带有 API 29 的 Android Studio 版本 3.6 并且我在此代码中的回收器视图适配器中遇到问题

@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()??为什么我不能使用 getContext()??

Because RecyclerView.Adapter doesn't have a getContext() method.因为RecyclerView.Adapter没有getContext()方法。 You can use parent.getContext() instead您可以改用parent.getContext()

RecyclerView.Adapter does not have a getContext() you need to use the parent context. RecyclerView.Adapter 没有您需要使用父上下文的 getContext() 。

@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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM