📜  如何在回收器视图适配器中获取上下文 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:42.856000             🧑  作者: Mango

代码示例1
private Context context;

@Override
public FeedAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,int viewType) {
    // create a new view
    View v=LayoutInflater.from(parent.getContext()).inflate(R.layout.feedholder, parent, false);
    // set the view's size, margins, paddings and layout parameters
    ViewHolder vh = new ViewHolder(v);
    // set the Context here 
    context = parent.getContext();
    return vh;
}