我想在 上显示下面的布局RecyclerView
。此布局根据商店数量而重复。假设我们有 2 家商店,那么用户将看到两种布局,具有不同的商店名称。
适配器类:
public class DeliverySlotsAdapter extends RecyclerView.Adapter<DeliverySlotsAdapter.ViewHolder> {
private Context context;
LayoutInflater layoutInflater;
List<Object> objects;
private LayoutInflater inflater;
private CallbackListener.SimpleCallback listener;
public DeliverySlotsAdapter(Context context, List<Object> objects) {
this.context = context;
this.objects = objects;
this.inflater = LayoutInflater.from(context);
public void setListener(CallbackListener.SimpleCallback listener) {
this.listener = listener;
}
@Override
public ViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
RecyclerView.ViewHolder viewHolder;
View view= inflater.inflate(R.layout.item_checkout_delivery_slots, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.bind(objects.get(position));
}
@Override
public int getItemCount() {
return objects.size() != 0 ? objects.size() : 0;
}
class ViewHolder extends RecyclerView.ViewHolder {
// @BindView(R.id.rlSchedule)
// RelativeLayout rlSchedule;
@BindView(R.id.tvDeliveryScheduleLabel)
TextView tvDeliveryScheduleLabel;
// @BindView(R.id.tvDeliverySchedule)
// TextView tvDeliverySchedule;
public ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(v -> {
if (listener!=null && getAdapterPosition() != RecyclerView.NO_POSITION) {
listener.onItemClick(objects.get(getAdapterPosition()));
}
});
}
神不在的星期二
扬帆大鱼
相关分类