Search code examples
androidkotlinandroid-edittextandroid-roomcalculated-columns

kotlin android rooom how to calculate data's from column with edit text?


As in the topic, how to multiplicate data from column with edit text in AdapterList? e.g.

class AdapterList (context: Context, val resource: Int, val objects: List<Opryski>) :
ArrayAdapter<Opryski>(context, resource, objects){
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val inflater = LayoutInflater.from(context)
val customView = inflater.inflate(resource, parent, false)
val area= customView.findViewById<EditText>(R.id.editTextSize)
val dose= customView.findViewById<TextView>(R.id.id_dose)
val name= customView.findViewById<TextView>(R.id.id_nazme)
val what= customView.findViewById<TextView>(R.id.id_what)
val when= customView.findViewById<TextView>(R.id.id_when)
val profilaktyka = customView.findViewById<TextView>(R.id.id_profilaktyka)

val item = objects.getOrNull(position)
if(item!=null)
{
    name.text = item.name
    dose.text = item.dose.toString() * area //<--- I want to multiplicate this//
    what.text = item.what
    when.text = item.when
    profilaktyka.text = item.profilaktyka
}

return customView }


Solution

  • You can try something like this:

    dose.setText((area.text.toString().toInt() * item.dose.text.toString().toInt()).toString())
    

    Because you get an editable from editext.text and then you convert it to string and then parse Int from that. Calculate whatever you want and then setText with string back.