我希望我的按钮可以检查字母是否在单词中
word: Hai
user pres btnA
result : _a_
user pres btnH
result : Ha_
这就是我在Kotlin Android Studio所做的
fun guessTry(click : View){
val guessW = txtKata.toString()
txtKata.text = null
if (click == btnA){
val a = btnA.text
if(a in secretWord.toLowerCase() || a in secretWord.toUpperCase() ){
corecGuess.add(guessW)
wordSecret()
}
}
}
word: Hai
user pres btnA
result : _a_
user pres btnH
result : Ha_
答案 0 :(得分:0)
我认为您可以尝试像这样更改if函数
fun guessTry(click : View){
val guessW = txtKata.toString()
txtKata.text = null
if (click == btnA){
val a = btnA.text
if(secretWord.toLowerCase().contains(a) || secretWord.toUpperCase().contains(a) ){
corecGuess.add(guessW)
wordSecret()
}
}
}