例如:
String name = "hello";
R.string.other生成的定义为:public static final int other=0x7f040002;如下语句显示的结果为:hello2130968578
myTextView.setText(name + R.string.other);setText只用R.string.other作为参数可以正常显示,只用name也可以正常显示,两者组合就不行了,不知道为啥。。?怎么能正确组合显示?
String name = "hello";
R.string.other生成的定义为:public static final int other=0x7f040002;如下语句显示的结果为:hello2130968578
myTextView.setText(name + R.string.other);setText只用R.string.other作为参数可以正常显示,只用name也可以正常显示,两者组合就不行了,不知道为啥。。?怎么能正确组合显示?
name 是字符串型setText方法里的参数可以是字符串,也可以是资源ID号。
//初始化
myTextView= (TextView) this.findViewById(R.id.other);
//赋值
myTextView.setText(name + myTextView.getText().toString());不知道你能不能看懂?
同样适合于取color等类似。
String text = getString(R.string.other, name);
myTextView.setText(text);
myTextView.setText(name + R.string.other)结果为:hello2130968578