selfstarter

Setting String format in Android 본문

App/Android

Setting String format in Android

selfstarter 2020. 4. 1. 09:55

Setting String format in Android

  1. strings.xml에서 string 추가

    <resources>
     <string name="app_name">StringFormatteExample</string>
     <string name="test_format_num">%d번째 입니다</string>
     <string name="test_format_string">%s 버튼 입니다</string>
     <string name="test_format_percent">%d %%입니다</string>
     <string name="test_format_dollar">%d$달러 입니다</string>
    </resources>
  2. MainActivity에서 format에 대한 값 지정 후 출력

    Resources res = getResources();
    String test_format_num = String.format(res.getString(R.string.test_format_num), 144);
    String test_format_string = String.format(res.getString(R.string.test_format_string), "확인");
    String test_format_percent = String.format(res.getString(R.string.test_format_percent), 10);
    String test_format_dollar = String.format(res.getString(R.string.test_format_dollar), 10);
    

'App > Android' 카테고리의 다른 글

Android adb command  (0) 2020.04.03
Android apk install  (0) 2020.04.01
Internal error in Firestore (0.6.6-dev)  (0) 2020.04.01
Animation simple example in Android  (0) 2020.03.30
Simple Current Time Example  (0) 2020.03.26
Comments