I have a database with a column called PoemTitle
, so I want to get the first letter from each title and give it a vector background with different colors.
Please, can anyone help me with a function to do so depending on the char type? Below is the code that I tried:
fun getHeaderFirstChar(poems:Poems, res: Resources) {
when (poems.PoemTitle.first()) {
'a'..'b' -> res.getbackground
}
}
That is the code I tried but it's not working
Note: language is Kotlin
and I'm using RoomDatabase
Don't re-invent the wheel, have a look at this library: https://github.com/amulyakhare/TextDrawable
and yes its Java but you can use it in Kotlin as well!