How to add layout inflator (Layout Inflators)
GridLayout coursesgrid=view.findViewById(R.id.coursesgrid);
LayoutInflater layoutInflater=getActivity().getLayoutInflater();
View inflaterview=layoutInflater.inflate(R.layout.coursecardtemplate,coursesgrid,false);
//your coding
ImageView courseimg=inflaterview.findViewById(R.id.courseimg);
TextView coursetext=inflaterview.findViewById(R.id.coursetext);
courseimg.setImageResource(drawables[i]);
coursetext.setText(coursesname[i]);
//
coursesgrid.addView(inflaterview);
For Multiple item to inflate
simply put all in loop
for(int i=0;i<courses.length;i++){
GridLayout coursesgrid=view.findViewById(R.id.coursesgrid);
LayoutInflater layoutInflater=getActivity().getLayoutInflater();
View inflaterview=layoutInflater.inflate(R.layout.coursecardtemplate,coursesgrid,false);
ImageView courseimg=inflaterview.findViewById(R.id.courseimg);
TextView coursetext=inflaterview.findViewById(R.id.coursetext);
courseimg.setImageResource(drawables[i]);
coursetext.setText(coursesname[i]);
coursesgrid.addView(inflaterview);
}
Comments
Post a Comment