Answers for "How to get a context in a recycler view adapter"

0

How to get a context in a recycler view adapter

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;
}
Posted by: Guest on September-14-2021

Code answers related to "How to get a context in a recycler view adapter"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language