1 | initial version |
To make the toast message appear upon the call of the function, you can use the following code:
fun showToastMessage(context: Context, message: String) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
}
Here, we have defined a function named showToastMessage
that takes two parameters: a Context
object and the message to be displayed in the toast. The function creates a new Toast
object by passing the context
, message
, and the duration of the toast (short or long) as parameters. Finally, it calls the show()
method to make the toast message appear.
To call this function, you can simply pass the required parameters to it like this:
showToastMessage(this, "Hello, World!")
Here, this
refers to the current activity or context, and "Hello, World!" is the message that you want to display in the toast. You can replace this with your own context object and message string as required.