Koltin40,android性能优化和内存优化

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()

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值