【发布时间】:2021-11-18 05:25:26
【问题描述】:
在本周的课堂上,我们的任务是创建一个简单的蛋糕烘焙应用。有两个编辑文本字段(湿文本、干文本),用户可以在其中输入要添加到蛋糕中的成分。添加成分后单击一个混合按钮。在 mixbutton 单击时,我的目标是将添加的成分从 editText 列出到新的 textView(cakeText) 中,如下所示:
您在击球手中添加了 ---!
您在击球手中添加了 ---!
您在击球手中添加了 ---!
等等
我们应该使用 for 循环,我想我可能通过使用数组走在正确的轨道上。 batterList 是我最近的尝试,所以我知道这是错误的,但我很想知道如何解决它!我已经工作了几个小时并且已经接近了,但还不够接近。我希望这是有道理的。在这一点上,我的头脑不正常。任何建议将不胜感激!
val wetList = mutableListOf<String>()
val dryList = mutableListOf<String>()
val batterList = arrayOf(wetList)
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
fun wetButtonTapped(view: View) {
wetList.add(wetText.text.toString())
wetText.text.clear()
ingredientList.text = "You have ${wetList.count()} wet ingredients \n You have ${dryList.count()} dry indredients"
}
fun dryButtonTapped(view: View) {
dryList.add(dryText.text.toString())
dryText.text.clear()
ingredientList.text = "You have ${wetList.count()} wet ingredients \n You have ${dryList.count()} dry indredients"
}
fun mixButtonTapped(view: View) {
//cakeText.text = "You added ${wetList}"
for (item in batterList){
cakeText.text = "You added $item to the batter!"
}
【问题讨论】:
-
请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。
标签: android arrays list kotlin android-edittext