问题描述
我正在构建一个 todoapp,它在对话框中输入文本后在活动上添加任务。没有任何重大问题。我以本教程为基础:https://medium.com/@tanunprabhu95/to-do-list-application-using-kotlin-using-android-studio-546e74ac75aa 我在 android studio 中测试了代码,它运行得非常好(他们不使用对话框)。因此,我尝试在我自己的项目中使用对话框复制代码。没有显示错误,但在我尝试添加另一个任务后,任务名称被替换。教程中甚至有代码可以防止这种情况发生。我认为对话框的行为与教程中显示的简单编辑文本不同。我不知道如何更改我的代码以避免此问题并使我的应用程序正常运行。也许是因为我使用了一个名为 MaterialDialog 的库,它的行为与“普通”对话框不同。你有什么建议吗?非常感谢您的帮助!
这是我的代码:
val dialog = MaterialDialog(this)
.noAutodismiss()
.customView(R.layout.activity_schedule)
dialog.getCustomView().findViewById<TextView>(R.id.positive_button).setonClickListener{
val name = dialog.getCustomView().findViewById<EditText>(R.id.task_name)
var itemlist = arraylistof<String>()
var adapter = ArrayAdapter(
this,android.R.layout.simple_list_item_multiple_choice,itemlist
)
itemlist.add(name.text.toString())
listView.adapter = adapter
adapter.notifyDataSetChanged()
// This is because every time when you add the item the input space or the eidt text space will be cleared
name.text.clear()
dialog.dismiss()
}
dialog.show()
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)