Search code examples
androidxmlstringandroid-preferences

How to escape '%' in android preferences


I have read this thread FATAL EXCEPTION main Android App and it is very helpful.

And YES this works nice

<string formatted="false">some text and % in the text</string>

so if someone uses xml the formatted="false" is the solution.

But I have problem in the code

getPreferenceScreen().findPreference("my_key").setSummary("some text and % in the text"));

and this trows an exception, does anybody knows how can I escape the % ?

so when the String.format() is called the % will be treated like '%' and not like an special character

Thanks


Solution

  • Just double it up! Instead of using one percent, use two. Like so.

    setSummary("some text and %% in the text")