首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将房间数据库的列与编辑文本进行倍增

如何将房间数据库的列与编辑文本进行倍增
EN

Stack Overflow用户
提问于 2021-04-22 18:49:15
回答 1查看 49关注 0票数 0

我有一个问题,是否有任何选项可以使用适配器中的可编辑编辑文本从房间中的列计算数据?适配器:

代码语言:javascript
运行
复制
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中,我们可以在这里输入我们的区域,程序应该显示该区域所需的计算农药剂量的列表

EN

回答 1

Stack Overflow用户

发布于 2021-04-23 03:34:10

您需要使用查询来执行此操作,并且还需要一个中间模型来执行此操作:

房间是一个SQLite包装器,因此SQLite上的所有有效内容通常也适用于房间

代码语言:javascript
运行
复制
//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中反映所有这些值

代码语言:javascript
运行
复制
data class DosedOpryski(
    val name: String, val what: String, val when: String, val multiplication: Int
)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67211765

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档