Issue
Im trying to set rating in rating bar while the API service returns a sting for rating field. couldn't find any way to use it directly in xml using databinding so I tried binding adapter and surprisingly the parseFloat
in Float.parseFloat()
is not recognizing by my IDE. I have tried this piece of code in other part of project like fragments but nothing happens.
Thanks for any idea and suggestion.
Solution
Kotlin doesn't have Float.parseFloat() method.
To convert string to float use toFloatOrNull(), this will convert string to float
var string = "5"
var floatNumber = string.toFloatOrNull()
Log.e(TAG, " string.toFloatOrNull() $floatNumber")
You can set this float value in rating bar
Answered By - Amanpreet Kaur
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.