title: How to make a function when pressing a button in KOTLIN
body: <p>I created a function called &quot;talk&quot; so I want to press a button to execute &quot;talk&quot;. 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 &quot;talk&quot; function is executed I want to make a condition. and I don't know how to do both when pressing the button.</p>
  <pre><code>imageButton.setOnClickListener{
  talk()
  if (textView3.text==&quot;hello&quot;) {
  textView.visibility = View.VISIBLE
  } else {
  
  }
  }
  </code></pre>
  <p>this is the code of the function &quot;&quot;talk&quot;&quot; :</p>
  <pre><code>fun talk(v: View) {
          val intentActionRecognizeSpeech = Intent(
                  RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
          // Configura el Lenguaje (Español-México)
          intentActionRecognizeSpeech.putExtra(
                  RecognizerIntent.EXTRA_LANGUAGE_MODEL, &quot;es-MX&quot;)
          try {
              startActivityForResult(intentActionRecognizeSpeech,
                      RECOGNIZE_SPEECH_ACTIVITY)
          } catch (a: ActivityNotFoundException) {
              Toast.makeText(applicationContext,
                      &quot;Tú dispositivo no soporta el reconocimiento por voz&quot;,
                      Toast.LENGTH_SHORT).show()
          }
      }
  }
  </code></pre>