I found a way how to get formatted string from strings.xml file.
I am going to show how I did it. Please refer to method.
strings.xml
<string name="text">My name is %s. I work at FaYnaSoft Labs %d months.</string>
Activity
getResources().getString(R.string.text, "Oleg Mazurashu", 7)
Example:
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
/**
* Activity which shows how to use formatted string from strings.xml
*
* @author FaYnaSoft Labs
*/
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.textId);
tv.setText(getResources().getString(R.string.text, "Oleg Mazurashu", 7));
}
}
I like this approach.
Related posts:

Recent Comments