Coupon onClick unfinished code

This commit is contained in:
Bart
2021-01-04 13:44:09 +01:00
parent d96a54863c
commit 547d676a68
2 changed files with 23 additions and 5 deletions

View File

@@ -42,10 +42,14 @@ public class CouponFragment extends Fragment {
CouponListManager.INSTANCE.load();
this.couponList = CouponListManager.INSTANCE.getCouponList();
this.couponAdapter = new CouponAdapter(this.getContext(), this.couponList);
this.couponAdapter = new CouponAdapter(this.getContext(), this.couponList, onClickedItem -> showPopup());
this.couponRecyclerView.setLayoutManager(this.layoutManager);
this.couponRecyclerView.setAdapter(this.couponAdapter);
return view;
}
private void showPopup() {
}
}

View File

@@ -1,6 +1,7 @@
package com.a1.nextlocation.recyclerview;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
@@ -24,10 +25,11 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
void onItemClick(int clickedPosition);
}
class CouponViewHolder extends RecyclerView.ViewHolder {
class CouponViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView couponCode;
private TextView couponReward;
private Coupon coupon;
public CouponViewHolder(@NonNull View itemView) {
super(itemView);
@@ -42,11 +44,22 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
this.couponReward = itemView.findViewById(R.id.coupon_waarde);
this.couponReward.setText(text);
}
public void setCoupon(Coupon coupon){
this.coupon = coupon;
}
public CouponAdapter(Context context, List<Coupon> coupon){
appContext = context;
couponList = coupon;
@Override
public void onClick(View v) {
Log.d("yeet", "Coupon code: " + coupon.getCode());
}
}
public CouponAdapter(Context context, List<Coupon> coupon, OnItemClickListener listener){
this.appContext = context;
this.couponList = coupon;
this.clickListener = listener;
}
@NonNull
@@ -59,6 +72,7 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
@Override
public void onBindViewHolder(@NonNull CouponViewHolder holder, int position) {
Coupon coupon = couponList.get(position);
holder.setCoupon(coupon);
holder.setTextViewCode(coupon.getCode());
holder.setTextViewReward(coupon.getReward());
}