Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Chip setoncheckedchangelistener字符串比较返回false_Android_Kotlin_Android Chips - Fatal编程技术网

Android Chip setoncheckedchangelistener字符串比较返回false

Android Chip setoncheckedchangelistener字符串比较返回false,android,kotlin,android-chips,Android,Kotlin,Android Chips,某些上下文:我正在根据日期筛选行程,这些行程在firebase上,我有一个方法(getTripState)将当前日期与行程日期进行比较,并根据具体情况返回“即将到来”或“旧行程”。芯片起到开关按钮的作用,并启用了单选功能。我过滤tripArray基于芯片文本等于行程中的日期。即使字符串完全相同,比较也返回false chipGroup.setOnCheckedChangeListener { chipGroup, i -> val chip: Chip = chipGrou

某些上下文:我正在根据日期筛选行程,这些行程在firebase上,我有一个方法(getTripState)将当前日期与行程日期进行比较,并根据具体情况返回“即将到来”或“旧行程”。芯片起到开关按钮的作用,并启用了单选功能。我过滤tripArray基于芯片文本等于行程中的日期。即使字符串完全相同,比较也返回false

chipGroup.setOnCheckedChangeListener { chipGroup, i ->
        val chip: Chip = chipGroup.findViewById(i)

        rvHome.adapter = TripHistoryAdaptor(context, tripsArray.filter {
            Toast.makeText(context, (it.date.getTripState() == chip.text).toString(), Toast.LENGTH_SHORT).show()
            Toast.makeText(context, "${it.date.getTripState()} == ${chip.text} ", Toast.LENGTH_SHORT).show()

            it.startAt.getTripState() === chip.text

        } as ArrayList<Trip>)

        (rvHome.adapter as TripHistoryAdaptor).notifyDataSetChanged()
    }
chipGroup.setOnCheckedChangeListener{chipGroup,i->
val chip:chip=chipGroup.findViewById(i)
rvHome.adapter=TripHistoryAdapter(上下文,tripsArray.filter{
Toast.makeText(context,(it.date.getTripState()==chip.text).toString(),Toast.LENGTH\u SHORT.show())
Toast.makeText(上下文,${it.date.getTripState()}==${chip.text}),Toast.LENGTH\u SHORT.show()
it.startAt.getTripState()==chip.text
}作为ArrayList)
(rvHome.adapter作为TripHistoryAdapter)。notifyDataSetChanged()
}

这可能是因为
区分大小写的比较。参见下面的示例

val first = "kotlin"
val second = "kotlin"
val firstCapitalized = "KOTLIN"

println(first == second) // output: True
print(first == firstCapitalized) // output: False [becuase uppercase and lowercase]
因此,您可以通过将字符串转换为
小写
来比较字符串,如下所示

val first = "kotlin"
val second = "kotlin"
val firstCapitalized = "KOTLIN"

println(first == second) // output: True
print(first.toLowerCase() == firstCapitalized.toLowerCase()) // output: True
另一种方法是,您可以对第二个可选参数
ignoreCase使用
equals方法
pass true

val first = "kotlin"
val second = "kotlin"
val firstCapitalized = "KOTLIN"

println(first.equals(second)) // output: True
print(first.equals(firstCapitalized, true)) // output: True

字符串完全相同。但还是失败了。感谢stry调试和检查it.date.getTripState()和chip.text的值,它们是相同的。