-1

I was trying to inflate a layout and i came across these two code.Can someone please tell me the difference between these two inflate method? I am new to android studio and i want to learn more about this inflate method. Also apart from these two are there any other way to inflate a layout?

public MyViewHolder onCreateViewHolder(ViewGroup parent,int viewType){
    View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.movie_list_row, parent, false);
    return new MyViewHolder(itemView);
}

and

LayoutInflater inflater = LayoutInflater.from(context);
    View rowView = inflater.inflate(R.layout.list_single, null, true);
    return rowView;
}
K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33
klaptor
  • 115
  • 10

1 Answers1

0

For getting a view (if need in fragment use inside of oncreate getLayoutInflater() replace the oncreateview inflater object)

 View v=getLayoutInflater().inflate(R.layout.activity_main2,null);

For getting a view for listview

View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_row,parent,false);
Raj
  • 477
  • 5
  • 20