Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this code here
Java
private fun plus(){
    val num1 = num1TextE.text.toString().toInt()
    val num2 = num2TextE.text.toString().toInt()
    if(checkEditTextEmpty()){
        resultText.visibility = View.VISIBLE
        var result = num1 + num2
        resultText.text = "Result is $result"
        num1TextE.text = // make it equal to result
    }
}


and i want to assign the num1TextE(which is an edit text).text to the result variable, but it says required Editable found Int.

What I have tried:

i tried to do some conversion but nothing worked.
Posted
Updated 3-Aug-19 10:59am

1 solution

Did you try to convert it to String and then applying?
Java
num1TextE.text = result.toString()
Basically what Kotlin is doing is just providing a high-level abstraction over Java, so in Java what you do is you normally set the text field of an EditText control with a String value... Just an integer needs to be converted to String and then used in the setText function—which Kotlin converts to a text setter.

See these for more on this topic,
EditText  |  Android Developers[^]
android - How do I set the text of an EditText to an Int? - Stack Overflow[^]
android - How does Kotlin property access syntax work for Java classes (i.e. EditText setText)? - Stack Overflow[^]

Oh, and Editable type is just a fancy underlying type for String, a String would work just fine.

Editable  |  Android Developers[^]
What is 'Editable' data type in Android? - Stack Overflow[^]
 
Share this answer
 
v2
Comments
hiwa doski 4-Aug-19 3:24am    
no that didn't worked, it still says required !Editable found String
David Crow 6-Aug-19 16:12pm    
Have you tried something like:
num1TextE?.setText(result)
hiwa doski 6-Aug-19 16:23pm    
Yes that works thanks, but why .text doesnt work ?
David Crow 6-Aug-19 16:24pm    
Don't know. I know zilch about Kotlin.
hiwa doski 6-Aug-19 17:00pm    
Okay thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900