我想在我的回收者视图中实施本机高级添加。但是我不知道如何实现它。这是我的代码。请提供一些帮助以实施本机高级添加。
这是我的回收站视图Java代码。
家庭片段:-
private CouponDealsAdapter couponDealsAdapter;
private List<CouponDeal> couponDeals;
couponDeals = new ArrayList<>();
couponDealsAdapter = new CouponDealsAdapter(getContext(), couponDeals);
recyclerViewCouponDeals = (RecyclerView) view.findViewById(R.id.couponDeals_recycler_view);
recyclerViewCouponDeals.setHasFixedSize(true);
recyclerViewCouponDeals.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
recyclerViewCouponDeals.setAdapter(couponDealsAdapter);
适配器类:-
public class CouponDealsAdapter extends RecyclerView.Adapter<CouponDealsAdapter.ViewHolder> {
public List<CouponDeal> couponDeals;
public Context context;
public CouponDealsAdapter(Context context, List<CouponDeal> couponDeals) {
this.couponDeals = couponDeals;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.coupons_deal, parent, false);
final ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(final CouponDealsAdapter.ViewHolder holder, final int position) {
if (TextUtils.isEmpty(couponDeals.get(position).getStore_name())) {
holder.store_name.setText("Not Available");
} else {
holder.store_name.setText(couponDeals.get(position).getStore_name());
}
if (TextUtils.isEmpty(couponDeals.get(position).getDeal_description())) {
holder.deal_description.setText("Not Available");
} else {
holder.deal_description.setText(couponDeals.get(position).getDeal_description() + ".");
}
if (TextUtils.isEmpty(couponDeals.get(position).getOffer_validity())) {
holder.offer_validity.setText("Not Available");
} else {
holder.offer_validity.setText(couponDeals.get(position).getOffer_validity());
}
if (TextUtils.isEmpty(couponDeals.get(position).getCoupon_code())) {
holder.coupon_code.setText("Not Available");
holder.coupon_code.setClickable(false);
} else {
holder.coupon_code.setText(couponDeals.get(position).getCoupon_code());
holder.coupon_code.setClickable(true);
}
if (TextUtils.isEmpty(couponDeals.get(position).getType())) {
holder.url.setText("SHOP NOW");
} else {
holder.url.setText("GET NOW");
}
holder.coupon_code.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("label", couponDeals.get(position).getCoupon_code());
clipboard.setPrimaryClip(clip);
Toast.makeText(context, "Code Copied to Clipboard", Toast.LENGTH_SHORT).show();
}
});
holder.url.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse(couponDeals.get(position).getUrl());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (intent.resolveActivity(context.getPackageManager()) != null) {
v.getContext().startActivity(intent);
}
}
});
if (TextUtils.isEmpty(couponDeals.get(position).getStore_image())) {
holder.store_image.setImageResource(R.drawable.failed_to_load_img);
holder.progressBar.setVisibility(View.GONE);
} else {
Picasso.with(context)
.load(couponDeals.get(position).getStore_image())
.into(holder.store_image, new Callback() {
@Override
public void onSuccess() {
holder.progressBar.setVisibility(View.GONE);
holder.imageViewFailed.setVisibility(View.GONE);
}
@Override
public void onError() {
holder.progressBar.setVisibility(View.GONE);
holder.imageViewFailed.setVisibility(View.VISIBLE);
}
});
}
}
@Override
public int getItemCount() {
return couponDeals.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView store_name;
public TextView deal_description;
public TextView offer_validity;
public ImageView store_image;
public Button url;
public ProgressBar progressBar;
public TextView coupon_code;
public ImageView imageViewFailed;
View mView;
public ViewHolder(View itemView) {
super(itemView);
mView = itemView;
store_name = (TextView) mView.findViewById(R.id.couponDeals_storeName);
deal_description = (TextView) mView.findViewById(R.id.couponDeals_description);
offer_validity = (TextView) mView.findViewById(R.id.couponDeals_validity);
store_image = (ImageView) mView.findViewById(R.id.couponDeals_store_image);
url = (Button) mView.findViewById(R.id.couponDeals_url);
progressBar = (ProgressBar) mView.findViewById(R.id.coupon_deal_progress);
coupon_code = (TextView) mView.findViewById(R.id.couponDeals_code);
imageViewFailed = (ImageView) mView.findViewById(R.id.featured_deal_img_failed_to_load);
}
}
}
请让我知道如何使用recyclerview以水平方式实现本机高级添加。使用自定义大小=来实现recyclerview和自定义文本颜色。 XML代码。