String-related issues and notes in string. xml
1. If you need to display some strings with variables, such as "1st lesson? How can I help you write code? Section 2nd ", such a string can be defined in string. xml:
Lesson % 1 $ d ?? % 2 $ s ?? Section % 3 $ d
Each space must be replaced by an escape character. The code automatically prompts the escape character. Note that you need to use 1 2 3 to differentiate multiple variables.
Ii. Use StringUtil. java tool class:
/*** String tool class * Created by dwayon. */public class StringUtil {/*** convert to the corresponding String */public static String format (Context context, int formatId, Object... args) {String format = context. getString (formatId); return String. format (Locale. getDefault (), format, args );}}
Iii. Usage:
String section = StringUtil. format (context, R. string. section, 1, "teach you to write code", 2 );
In this way, you can get "1st class hours? How can I help you write code? Section 2nd "this is a string.