I created a function called "talk" so I want to press a button to execute "talk". I put this to do in the activity_main.xml and everything works fine. The problem comes when I don't want to do it by activity_main but by code in Mainactivity.kt. After the "talk" function is executed I want to make a condition. and I don't know how to do both when pressing the button.
imageButton.setOnClickListener{
talk()
if (textView3.text=="hello") {
textView.visibility = View.VISIBLE
} else {
}
}
this is the code of the function ""talk"" :
fun talk(v: View) {
val intentActionRecognizeSpeech = Intent(
RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
// Configura el Lenguaje (Espa?ol-México)
intentActionRecognizeSpeech.putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL, "es-MX")
try {
startActivityForResult(intentActionRecognizeSpeech,
RECOGNIZE_SPEECH_ACTIVITY)
} catch (a: ActivityNotFoundException) {
Toast.makeText(applicationContext,
"Tú dispositivo no soporta el reconocimiento por voz",
Toast.LENGTH_SHORT).show()
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…