2011-05-02 5 views

답변

70
<string name="meatShootingMessage">You shot %1$d pounds of meat!</string> 


int numPoundsMeat = 123; 
String strMeatFormat = getResources().getString(R.string.meatShootingMessage); 
String strMeatMsg = String.format(strMeatFormat, numPoundsMeat); 

예 예, 당신이 사용할 수있는 here

+32

참고로, Resources.getString (INT 잔유는 ... formatArgs 객체) 자원 ID를 소요 및 String.format()와 유사한 또 다른 방법이며 Object 인수 마지막 단계를 건너 뛸 수 있습니다. – Josh

+8

플래그 '문서 : http://developer.android.com/reference/java/util/Formatter.html –

-2

에서 가져옵니다. string.xml 파일에 태그를 추가 한 다음 .java 파일에서 태그를 다시 찾은 후에는이 작업을 수행 할 수 있습니다. .

AndriodApp

문자열의 GetResources STR =()에는 getString (R.string.name);

33

getString() 함수를 formatArgs 객체로 전달하십시오.

int nextResultsSize = getNextResultsSize(); 
String strNextResultsSize = 
    getResources().getString(R.string.next_x_results, nextResultsSize); 

XML이 :

<string name="next_x_results">Next %1$d results</string> 
3
<string name="meatShootingMessage">You shot %1$d pounds of meat! Put Second Variable String here %$s and third variable integer here %3$d</string> 
int intVariable1 = 123; 
int stringVariable2 = "your String"; 
int intVaribale3 = 456; 
String strMeatFormat = getResources().getString(R.string.meatShootingMessage, intVariable1, stringVariable2 , intVaribale3); 
관련 문제