一种检测默认值未更改和清理代码的方法。科特林
我已经在kotlin
中编码了几个月。我仍然有很多东西要学我知道这一点。我有一块代码,我的脑海中应该有效。我对它的外观不满意,我觉得可以更好地完成它。
有人可以帮助我向我展示正确的方式做我目前想做的事情。
btnSend.setOnClickListener {
var x =0
var exceptionList = ArrayList(partsList.filter { (it.Exception) })
exceptionList.forEach {
if(it.EReason.contains("Select a reason")){x=1}}
if( x == 1 ){
val builder = AlertDialog.Builder(this)
builder.setMessage("Please select a reason for the current exception")
// Toast.makeText(context,"Data capture canceled",Toast.LENGTH_LONG).show()
builder.setIcon(android.R.drawable.ic_dialog_alert)
builder.setNeutralButton("Cancel"){dialogInterface , which ->
}
val alertDialog: AlertDialog = builder.create()
alertDialog.setCancelable(true)
alertDialog.show()
}else{ ...
代码的目的是查看我的arrayList
,并找出一个字段exceptionList [x] .EREASON
仍然包含默认值,并且尚未更改。该字段由我的spinner
填充我的recylerview
。 it.exception
是复选框
,它仅将我的数组过滤到所选项目。
I have been coding in Kotlin
for a few months now. I still have a lot to learn I know this. I have a piece of code that in my head should work. I am not happy with how it looks, and I feel it can be done in a better way.
Can someone please help show me the right way of doing what I am currently want to do.
btnSend.setOnClickListener {
var x =0
var exceptionList = ArrayList(partsList.filter { (it.Exception) })
exceptionList.forEach {
if(it.EReason.contains("Select a reason")){x=1}}
if( x == 1 ){
val builder = AlertDialog.Builder(this)
builder.setMessage("Please select a reason for the current exception")
// Toast.makeText(context,"Data capture canceled",Toast.LENGTH_LONG).show()
builder.setIcon(android.R.drawable.ic_dialog_alert)
builder.setNeutralButton("Cancel"){dialogInterface , which ->
}
val alertDialog: AlertDialog = builder.create()
alertDialog.setCancelable(true)
alertDialog.show()
}else{ ...
The aim of the code is to look trough my arraylist
and find out if one of the fields exceptionlist[x].EReason
still contains the default value and has not been changed. The field is populated by a spinner
inside my Recylerview
. it.Exception
is a checkbox
that filters my array to only the selected items.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能可以重写此部分:
AS:
You can probably rewrite this part:
as: