public class GalleryGridAdapter extends RecyclerView.Adapter<GalleryGridAdapter.ViewHolder> {
private CompanyFragment mContext;
private ArrayList<CompanyObject> imageList;
public GalleryGridAdapter(CompanyFragment mContext, ArrayList<CompanyObject> imageList){
this.mContext=mContext;
this.imageList=imageList;
}
public interface ItemClickListener {
void onItemClick(int position);
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_choose_company, parent, false);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CompanyMenuFragment newFragment = new CompanyMenuFragment();
((AppCompatActivity) itemView.getContext()).getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, newFragment)
.addToBackStack(null)
.commit();
}
});
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
CompanyObject image = imageList.get(position);
Glide.with(mContext).load(image.getCompanyImage()).into(holder.imageGallery);
}
@Override
public int getItemCount() {
if(imageList==null) return 0;
return imageList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ImageView imageGallery;
public ViewHolder(View view) {
super(view);
imageGallery = itemView.findViewById(R.id.tile_picture);
}
}
}