我有一个问题,是否有任何选项可以使用适配器中的可编辑编辑文本从房间中的列计算数据?适配器:
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
}
}
EditText在activity_main.xml中,我们可以在这里输入我们的区域,程序应该显示该区域所需的计算农药剂量的列表
发布于 2021-04-22 19:34:10
您需要使用查询来执行此操作,并且还需要一个中间模型来执行此操作:
房间是一个SQLite包装器,因此SQLite上的所有有效内容通常也适用于房间
//I'm using a raw string here, triple quotes so I can write without minding the line breaks
@Query("""SELECT
name as name,
what as what,
when as when,
(dose * :area) as multiplication
FROM Opryski
""")
fun observeOpryskiesWithCalculatedDose(area: Int): LiveData<DosedOpryski>
如您所见,这里有something as something
,这是因为我们将在DosedOpryski
中反映所有这些值
data class DosedOpryski(
val name: String, val what: String, val when: String, val multiplication: Int
)
https://stackoverflow.com/questions/67211765
复制