RecyclerViewViewHolder

RecyclerViewViewHolder

我正在尝试以编程方式设置Recyclerview,请帮助。

public RecyclerViewViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_view_item /- how to do it here from custom view  class?/, parent, false);
    RecyclerViewViewHolder recyclerViewViewHolder = new RecyclerViewViewHolder(view);
    return recyclerViewViewHolder;
}

最佳答案

调用您的自定义视图的构造函数:

public RecyclerViewViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = new MyCustomView(parent.getContext());
    RecyclerViewViewHolder recyclerViewViewHolder = new RecyclerViewViewHolder(view);
    return recyclerViewViewHolder;
}

08-04 07:40