// this my PersonList Aadapter where I want to show in every item of the list the total of all scores of all the items // I tried this but the score always shows 0.0 as if it's not counting // I tried initializing the everything in the begin but I got the same result
class PersonListAdapter(
private var context: Context,
private var onItemClickListener: OnItemClickListener
) : RecyclerView.Adapter<PersonListAdapter.ViewHolder>() {
// this is the list of persons
private var mArrayList: ArrayList<Person> = ArrayList()
var total : Double=0.0
// this where I set the list
fun setList(mArrayList: ArrayList<Person>) {
this.mArrayList.clear()
this.mArrayList = mArrayList
notifyDataSetChanged()
}
//I tried this init by the total is always 0.0 and the list contains certain items
init {
mArrayList.forEach {item->
total += item.score?.toDouble()!!
}
}
// I tried this but the score always shows 0.0 as if it's not counting
// I tried initializing the everything in the begin but I got the same
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(mArrayList[position])
}
// I tried this but the score always shows 0.0 as if it's not counting
inner class ViewHolder(var view: View) : RecyclerView.ViewHolder(view) {
fun bind(personBean: Person) {
itemView.tvPersonPhone.text = personBean.delai
itemView.tvwiouw2.text = personBean.security
var score= personBean.security.toString().toDouble()+personBean.delai.toString().toDouble()
itemView.tvwiouw3.text = score.toString()
itemView.tvwiouw4.text =total.toString()
}
}
}