How to post text to a text box insted of a toast?

118 views Asked by At

Hey there people I'm new to Android and Kotlin can you help me with this please.

recognizer.recognize(ink)
            .addOnSuccessListener { result: RecognitionResult ->
                Toast.makeText(context, "I see ${result.candidates[0].text}", Toast.LENGTH_LONG)
                    .show()
            }

here the results is posted to a toast and I want it to be in a text box how to do that ?

2

There are 2 answers

0
Chenxi Song On

You will need to define a TextView in your layout file and then setText(...) with the detection result you get in onSuccessListener.

0
gary23w On

You could use a SnackBar. Add this to your code:

    fun showSnackBar(message: String) {
    val snackBar =
        Snackbar.make(findViewById(android.R.id.content), message, 
    Snackbar.LENGTH_LONG)
    val snackBarView = snackBar.view
    snackBarView.setBackgroundColor(
        ContextCompat.getColor(
            this@BaseActivity,
            R.color.PUTCOLORHERE
        )
    )
    snackBar.show()
}

You could replace your toast like this:

recognizer.recognize(ink)
        .addOnSuccessListener { result: RecognitionResult ->
          showSnackBar("PUT WORDS HERE")
        }