-1
ANDROID KOTLIN : Next: I have my Data Class with its variables,I make a call to the api and I get in my Adapter the list size to add to my attributes in xml ok.. wanted in Activity I put the amount of items I received from the api for example: if there are 3 items created in the layout show: there are 3 pending tasks and etc...
insira o código aqui
Moving class Downloadapter2 : Recyclerview.Adapter<Moving>() {
val mRetornaItens: MutableList<RetornaItensModel2> = mutableListOf()
inner class MovimentacaoVh2(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(retornaItensModel2: RetornaItensModel2) {
itemView.txt_api_numeroserie.text = retornaItensModel2.numeroSerie
itemView.txt_api_endereço.text = retornaItensModel2.enderecoVisual
itemView.txt_api_data.text = formatDate(retornaItensModel2.dataInclusao)
}
}
fun formatDate(date: String): String {
val dateTime =
LocalDateTime.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"))
val formatter = DateTimeFormatter.ofPattern("dd/MM/yy - HH:mm")
val formatted = dateTime.format(formatter)
return formatted.toString()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MovimentacaoVh2 {
val inflate = LayoutInflater.from(parent.context)
.inflate(R.layout.item_retorna_itens_mov2, parent, false)
return MovimentacaoVh2(inflate)
}
override fun onBindViewHolder(holder: MovimentacaoVh2, position: Int) {
holder.bind(mRetornaItens[position])
}
override fun getItemCount() = mRetornaItens.size
fun Update(it: List<RetornaItensModel2>) {
mRetornaItens.addAll(it)
notifyDataSetChanged()
}
fun remove(position: Int) {
mRetornaItens.removeAt(position)
notifyItemRemoved(position)
notifyDataSetChanged()
}
In my book I wanted to do this: val Sizelits.text = "Total pensent tasks : ${ ......}"
I’ll try very hard thank you!!!
– Gabriel Felski
I tried but always returns 0,I’m not understanding...she inflates my cardView for example I have 3 cardView,wanted to show there are 3 tasks and so on...
– Gabriel Felski
If it is returning 0, it must be because you did not initialize Adapter with the task list before calling the list to show in Textview. Make sure the list is actually filled with the items.
– Louix Dev
Managed to solve?
– Louix Dev
Oh yeah I got it straight from the body
– Gabriel Felski
Great, mark your question as resolved. Success for you!
– Louix Dev