Android question mark in TextView?

4k Views Asked by At

I have a problem with accented characters in a TextView in an Android activity. The rendering shows me question marks instead chars "è" and "à". The flow is: Get a midi file from web resource --> extract lyrics --> put lyrics in a TextView. I don't understand if is a problem with encoding or charset. I try to encode a file with "UTF-8" or "ISO..." but every attempt failed. Can you help me?

Thanks in advance.

3

There are 3 best solutions below

1
On

You can try something like this before you put the lyrics into a textview:

newLyrics = new String(oldString.getBytes("UTF-8"),"UTF-8");
0
On

You can try below code:

//String encode function
fun encodeEmoji(message: String): String {
    try {
        return URLEncoder.encode(
            message,
            "UTF-8"
        )
    } catch (e: UnsupportedEncodingException) {
        return message
    }

}


//String decode function
fun decodeEmoji(message: String): String {
    val myString: String? = null
    try {
        return URLDecoder.decode(
            message, "UTF-8"
        )
    } catch (e: UnsupportedEncodingException) {
            return message
    }

}

use of function

    var string:String=CommonMethod.encodeEmoji("your string")

    string=CommonMethod.decodeEmoji(string)
0
On

Check this out once:

https://www.csie.ntu.edu.tw/~r92092/ref/midi/

Midi files basically comprises of binary format + ascii values as header data, so if you can convert that and represent it like-
If you can encode that binary format to base64, this will turn any data into ascii safe text