Search code examples
androidkotlinandroid-edittext

Convert EditText text to uppercase and lowercase , when clicked on button?


What i am trying to do is take input from the user and on button click event i want to display that EditText input on TextView. On button click listener, textView should display the input string in All caps and then clicking the same button it should convert that string into lowercase an show it on TextView. How can I achieve this?

This is what i have tried.

var userInput = findViewById<EditText>(R.id.editText)
var caseButton = findViewById<Button>(R.id.upperLowerButton)
var caseView = findViewById<TextView>(R.id.textUpperLower)

caseButton.setOnClickListener {
    caseView.text =  userInput.text
}

Solution

  • You can use something like:

    val uppercase = userInput.text.toString().toUpperCase()
    val lowerCase = uppercase.toLowerCase()