Coupon onClick unfinished code
This commit is contained in:
@@ -42,10 +42,14 @@ public class CouponFragment extends Fragment {
|
|||||||
CouponListManager.INSTANCE.load();
|
CouponListManager.INSTANCE.load();
|
||||||
this.couponList = CouponListManager.INSTANCE.getCouponList();
|
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.setLayoutManager(this.layoutManager);
|
||||||
this.couponRecyclerView.setAdapter(this.couponAdapter);
|
this.couponRecyclerView.setAdapter(this.couponAdapter);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showPopup() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.a1.nextlocation.recyclerview;
|
package com.a1.nextlocation.recyclerview;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -24,10 +25,11 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
|
|||||||
void onItemClick(int clickedPosition);
|
void onItemClick(int clickedPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
class CouponViewHolder extends RecyclerView.ViewHolder {
|
class CouponViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
|
||||||
private TextView couponCode;
|
private TextView couponCode;
|
||||||
private TextView couponReward;
|
private TextView couponReward;
|
||||||
|
private Coupon coupon;
|
||||||
|
|
||||||
public CouponViewHolder(@NonNull View itemView) {
|
public CouponViewHolder(@NonNull View itemView) {
|
||||||
super(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 = itemView.findViewById(R.id.coupon_waarde);
|
||||||
this.couponReward.setText(text);
|
this.couponReward.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCoupon(Coupon coupon){
|
||||||
|
this.coupon = coupon;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Log.d("yeet", "Coupon code: " + coupon.getCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CouponAdapter(Context context, List<Coupon> coupon){
|
public CouponAdapter(Context context, List<Coupon> coupon, OnItemClickListener listener){
|
||||||
appContext = context;
|
this.appContext = context;
|
||||||
couponList = coupon;
|
this.couponList = coupon;
|
||||||
|
this.clickListener = listener;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -59,6 +72,7 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull CouponViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull CouponViewHolder holder, int position) {
|
||||||
Coupon coupon = couponList.get(position);
|
Coupon coupon = couponList.get(position);
|
||||||
|
holder.setCoupon(coupon);
|
||||||
holder.setTextViewCode(coupon.getCode());
|
holder.setTextViewCode(coupon.getCode());
|
||||||
holder.setTextViewReward(coupon.getReward());
|
holder.setTextViewReward(coupon.getReward());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user