Advertisement
Guest User

Adapter

a guest
Mar 22nd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. package com.studio.faisal.banjarmasin.Lokasi;
  2.  
  3. import android.content.Context;
  4. import android.support.v7.widget.RecyclerView;
  5. import android.view.LayoutInflater;
  6. import android.view.View;
  7. import android.view.ViewGroup;
  8. import android.widget.ImageView;
  9. import android.widget.TextView;
  10.  
  11. import com.studio.faisal.banjarmasin.R;
  12.  
  13. import java.util.List;
  14.  
  15. /**
  16. * Created by Faisal on 19/02/2019.
  17. */
  18.  
  19. public class HotelAdapter extends RecyclerView.Adapter<HotelAdapter.HotelViewHolder> {
  20. //this context we will use to inflate the layout
  21. private Context mCtx;
  22.  
  23. //we are storing all the products in a list
  24. private List<ListData> productList;
  25.  
  26. //getting the context and product list with constructor
  27. public HotelAdapter(Context mCtx, List<ListData> productList) {
  28. this.mCtx = mCtx;
  29. this.productList = productList;
  30. }
  31.  
  32. @Override
  33. public HotelViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  34. //inflating and returning our view holder
  35. LayoutInflater inflater = LayoutInflater.from(mCtx);
  36. View view = inflater.inflate(R.layout.model, null);
  37. return new HotelViewHolder(view);
  38. }
  39.  
  40. @Override
  41. public void onBindViewHolder(HotelViewHolder holder, int position) {
  42. //getting the product of the specified position
  43. ListData product = productList.get(position);
  44. //binding the data with the viewholder views
  45. holder.textViewTitle.setText(product.getTitle());
  46. holder.textViewShortDesc.setText(product.getShortdesc());
  47. holder.imageView.setImageDrawable(mCtx.getResources().getDrawable(product.getImage()));
  48.  
  49. }
  50. @Override
  51. public int getItemCount() {
  52. return productList.size();
  53. }
  54.  
  55. class HotelViewHolder extends RecyclerView.ViewHolder {
  56.  
  57. TextView textViewTitle, textViewShortDesc;
  58. ImageView imageView;
  59. TextView textklik;
  60.  
  61. public HotelViewHolder(View itemView) {
  62. super(itemView);
  63. textViewTitle = itemView.findViewById(R.id.textViewTitle);
  64. textViewShortDesc = itemView.findViewById(R.id.textViewShortDesc);
  65. textklik = itemView.findViewById(R.id.textklik);
  66. imageView = itemView.findViewById(R.id.imageView);
  67.  
  68.  
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement