2014-04-15 5 views
0

나는 문자열안드로이드 동적 언어 문자열

<string name="body_activity_welcome">Hello! <br />This is the welcome page. Only logged in users can see this page.</string> 

선언했습니다하지만 난 개인적으로 사용자

<string name="body_activity_welcome">Hello {$username}! <br />This is the welcome page. Only logged in users can see this page.</string> 

를 가져 오는 경우 언어 문자열로 데이터를 전달하는 방법이 있나요 인사 싶어?

TextView text = (TextView) findViewById(R.id.register_status_message); 
    text.setText(R.string.body_activity_welcome); // somehow pass username to the string? 

답변

2

당신은 getString()을 사용하고 %1$s{$username}를 교체해야합니다. 인수 번호

$ s 님에게 다음과 같습니다 :

퍼센트 1

가에서 getString 첫 번째 인수는 자원 ID입니다 유형

입니다, 당신은 가변 인자를 가지고있는 문자열에 전달하려는 모든 데이터입니다.

getString(R.string.body_activity_welcome, userName); 

TextView text = (TextView) findViewById(R.id.register_status_message); 
text.setText(getString(R.string.body_activity_welcome, username)); //