SHARE
TWEET

Untitled

a guest Oct 18th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package cz.johngalt.app.taxiSelection;
  2.  
  3. /**
  4.  * Created by Aleksandre on 9/15/2019.
  5.  */
  6.  
  7. import android.content.Context;
  8. import android.support.v7.widget.RecyclerView;
  9. import android.view.LayoutInflater;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.ImageView;
  13. import android.widget.TextView;
  14.  
  15. import java.util.List;
  16.  
  17. import cz.johngalt.app.R;
  18.  
  19.  
  20. public class TaxiAdapter extends RecyclerView.Adapter<TaxiAdapter.ProductViewHolder> {
  21.  
  22.  
  23.     TaxiActivity taxiActivity;
  24.     Taxi taxi;
  25.     //this context we will use to inflate the layout
  26.     private Context mCtx;
  27.  
  28.     //we are storing all the products in a list
  29.     private List<Taxi> taxiList;
  30.  
  31.     //getting the context and product list with constructor
  32.     public TaxiAdapter(Context mCtx, List<Taxi> taxiList) {
  33.         this.mCtx = mCtx;
  34.         this.taxiList = taxiList;
  35.         taxiActivity = (TaxiActivity) mCtx;
  36.     }
  37.  
  38.     @Override
  39.     public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  40.         //inflating and returning our view holder
  41.         LayoutInflater inflater = LayoutInflater.from(mCtx);
  42.  
  43.         View view = inflater.inflate(R.layout.layout_taxi, null);
  44.  
  45.         ProductViewHolder holder = new ProductViewHolder(view);
  46.         return (holder);
  47.     }
  48.  
  49.     @Override
  50.     public void onBindViewHolder(ProductViewHolder holder, int position) {
  51.         //getting the product of the specified position
  52.         final Taxi taxi = taxiList.get(position);
  53.         //final TaxiActivity taxiActivity = new TaxiActivity();
  54.         //binding the data with the viewholder views
  55.         holder.textViewTitle.setText(taxi.getTitle());
  56.         holder.textViewShortDesc.setText(taxi.getShortdesc());
  57.         holder.textViewRating.setText(String.valueOf(taxi.getWaiting()));
  58.         holder.textViewPrice.setText(String.valueOf(taxi.getPrice()));
  59.  
  60.         holder.imageView.setImageDrawable(mCtx.getResources().getDrawable(taxi.getImage()));
  61.         holder.call_image_view.setImageDrawable(mCtx.getResources().getDrawable(taxi.getCall_image()));
  62.  
  63.         holder.itemView.setOnClickListener(new View.OnClickListener() {
  64.             @Override
  65.             public void onClick(View view) {
  66.                 taxiActivity.callToTaxi(taxi.getPhoneNumber(), "Calling to taxi");
  67.             }
  68.         });
  69.     }
  70.  
  71.  
  72.     @Override
  73.     public int getItemCount() {
  74.         return taxiList.size();
  75.     }
  76.  
  77.  
  78.     class ProductViewHolder extends RecyclerView.ViewHolder {
  79.  
  80.         TextView textViewTitle, textViewShortDesc, textViewRating, textViewPrice;
  81.         ImageView imageView, call_image_view;
  82.  
  83.         public ProductViewHolder(View itemView) {
  84.             super(itemView);
  85.  
  86.             textViewTitle = itemView.findViewById(R.id.textViewTitle);
  87.             textViewShortDesc = itemView.findViewById(R.id.textViewShortDesc);
  88.             textViewRating = itemView.findViewById(R.id.textViewRating);
  89.             textViewPrice = itemView.findViewById(R.id.textViewPrice);
  90.             imageView = itemView.findViewById(R.id.imageView);
  91.             call_image_view = itemView.findViewById(R.id.callToReserve);
  92.         }
  93.     }
  94. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top