var goodsList: List = ArrayList()
fun setDatas(goodsInfoList: List) {
this.goodsList = goodsInfoList
notifyDataSetChanged()
}
inner class GoodsItemHolder(itemView: View) : View.OnClickListener {
override fun onClick(v: View?) {
TODO(“Not yet implemented”)
}
val ivIcon: ImageView
val tvName: TextView
val tvForm: TextView
val tvMonthSale: TextView
val tvNewPrice: TextView
val tvOldPrice: TextView
val btnAdd: ImageButton
val btnMinus: ImageButton
val tvCount: TextView
lateinit var goodsInfo: GoodsInfo
init {
ivIcon = itemView.find(R.id.iv_icon)
tvName = itemView.find(R.i
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
d.tv_name)
tvForm = itemView.find(R.id.tv_form)
tvMonthSale = itemView.find(R.id.tv_month_sale)
tvNewPrice = itemView.find(R.id.tv_newprice)
tvOldPrice = itemView.find(R.id.tv_oldprice)
tvCount = itemView.find(R.id.tv_count)
btnAdd = itemView.find(R.id.ib_add)
btnMinus = itemView.find(R.id.ib_minus)
btnAdd.setOnClickListener(this)
btnMinus.setOnClickListener(this)
}
fun bindData(goodsInfo: GoodsInfo) {
this.goodsInfo = goodsInfo
//图片路径http://127.0.0.1:8090/image?name=takeout/businessimg/goods/0.jpg
Picasso.with(context).load(host + goodsInfo.icon).into(ivIcon)
tvName.text = goodsInfo.name
// tvForm.text = goodsInfo.form
tvMonthSale.text = “月售${goodsInfo.monthSaleNum}份”
tvNewPrice.text = PriceFormater.format(goodsInfo.newPrice.toFloat())
// tvNewPrice.text = “$${goodsInfo.newPrice}”
tvOldPrice.text = “¥${goodsInfo.oldPrice}”
tvOldPrice.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
if (goodsInfo.oldPrice > 0) {
tvOldPrice.visibility = View.VISIBLE
} else {
tvOldPrice.visibility = View.GONE
}
// tvCount.text = goodsInfo.count.toString()
if (goodsInfo.count > 0) {
tvCount.visibility = View.VISIBLE
btnMinus.visibility = View.VISIBLE
} else {
tvCount.visibility = View.INVISIBLE
btnMinus.visibility = View.INVISIBLE
}
}
}
override fun getCount(): Int {
return goodsList.size
}
override fun getItem(position: Int): Any {
return goodsList.get(position)
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
var itemView: View
val goodsItemHolder: GoodsItemHolder
if (convertView == null) {
itemView = LayoutInflater.from(context).inflate(R.layout.item_goods, parent, false)
goodsItemHolder = GoodsItemHolder(itemView)
itemView.tag = goodsItemHolder
} else {
itemView = convertView
goodsItemHolder = convertView.tag as GoodsItemHolder
}
goodsItemHolder.bindData(goodsList.get(position))
return itemView
}
override fun getHeaderView(position: Int, convertView: View?, parent: ViewGroup?): View {
val goodsInfo: GoodsInfo = goodsList.get(position)
val typeName = goodsInfo.typeName
val textView: TextView = LayoutInflater.from(context).inflate(R.layout.item_type_header, parent, false) as TextView
textView.text = typeName
textView.setTextColor(Color.BLACK)
return textView
}
override fun getHeaderId(position: Int): Long {
val goodsInfo: GoodsInfo = goodsList.get(position)
return goodsInfo.typeId.toLong()
}