kotlin android room 如何计算带有编辑文本的列的数据?
kotlin android rooom how to calculate data's from column with edit text?
如题中所述,AdapterList中如何将列中的数据与编辑文本相乘?
例如
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 自定义视图
}
您可以尝试这样的操作:
dose.setText((area.text.toString().toInt() * item.dose.text.toString().toInt()).toString())
因为您从 editext.text
获得可编辑的内容,然后将其转换为 string
,然后从中解析 Int
。计算任何你想要的,然后 setText
返回字符串。
如题中所述,AdapterList中如何将列中的数据与编辑文本相乘? 例如
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 自定义视图 }
您可以尝试这样的操作:
dose.setText((area.text.toString().toInt() * item.dose.text.toString().toInt()).toString())
因为您从 editext.text
获得可编辑的内容,然后将其转换为 string
,然后从中解析 Int
。计算任何你想要的,然后 setText
返回字符串。