version:1.0.0
update:更换包名 bugfixes:
This commit is contained in:
84
app/src/main/java/com/xxpatx/os/adapter/NewGoodsAdapter.java
Normal file
84
app/src/main/java/com/xxpatx/os/adapter/NewGoodsAdapter.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package com.xxpatx.os.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.shehuan.niv.NiceImageView;
|
||||
import com.xxpatx.os.R;
|
||||
import com.xxpatx.os.activity.details.DetailsActivity;
|
||||
import com.xxpatx.os.activity.GoodsActivity;
|
||||
import com.xxpatx.os.bean.GoodsInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NewGoodsAdapter extends RecyclerView.Adapter<NewGoodsAdapter.GoodsHolder> {
|
||||
|
||||
private Context mContext;
|
||||
private List<GoodsInfo> goodsInfoList;
|
||||
|
||||
public void setGoodsInfoList(List<GoodsInfo> list) {
|
||||
this.goodsInfoList = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public GoodsHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
mContext = parent.getContext();
|
||||
return new NewGoodsAdapter.GoodsHolder(LayoutInflater.from(mContext).inflate(R.layout.item_new_goods, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull GoodsHolder holder, int position) {
|
||||
GoodsInfo goodsInfo = goodsInfoList.get(position);
|
||||
Glide.with(holder.nv_goods_pic).load(goodsInfo.getImg()).error(mContext.getResources().getDrawable(R.drawable.nodata)).into(holder.nv_goods_pic);
|
||||
holder.root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mContext.startActivity(new Intent(mContext, GoodsActivity.class));
|
||||
}
|
||||
});
|
||||
holder.tv_goods_title.setText(goodsInfo.getGoods_desc());
|
||||
holder.tv_goods_pirce.setText("热卖促销¥" + goodsInfo.getBuying_price());
|
||||
holder.tv_buy.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(mContext, DetailsActivity.class);
|
||||
intent.putExtra("GoodsInfo", goodsInfo);
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return goodsInfoList == null ? 0 : goodsInfoList.size();
|
||||
}
|
||||
|
||||
static class GoodsHolder extends RecyclerView.ViewHolder {
|
||||
ConstraintLayout root;
|
||||
NiceImageView nv_goods_pic;
|
||||
TextView tv_goods_title;
|
||||
TextView tv_goods_pirce;
|
||||
TextView tv_buy;
|
||||
|
||||
public GoodsHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
root = itemView.findViewById(R.id.root);
|
||||
nv_goods_pic = itemView.findViewById(R.id.nv_goods_pic);
|
||||
tv_goods_title = itemView.findViewById(R.id.tv_goods_title);
|
||||
tv_goods_pirce = itemView.findViewById(R.id.tv_goods_pirce);
|
||||
tv_buy = itemView.findViewById(R.id.tv_buy);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user