R.string.Conversation包含Conversation
以下是代码:
tv.setText(R.string.Converasation+"HELLo");
textview控件正在将R.string.Conversation的int值和字符串值HELLO拼接起来,最终显示2131034187Hello,但我想要的是ConversationHello。
如何解决这个问题。
R.string.Conversation包含Conversation
以下是代码:
tv.setText(R.string.Converasation+"HELLo");
textview控件正在将R.string.Conversation的int值和字符串值HELLO拼接起来,最终显示2131034187Hello,但我想要的是ConversationHello。
如何解决这个问题。
试试看
tv.setText(getString(R.string.Converasation) + "HELLo");
Marc.
它应该像这样:
tv.setText(getString(R.string.Converasation)+" Hello ");
提醒一下,您可以使用 getString(int) 或者 getText(int) 方法来获取一个字符串。
@ Mudassir,一切运行良好。 对我来说是这样的:
display.setText(getText(R.string.counting_result) + " "+ counter);
Resources res = context.getResources();
float floatConverasation = 1.1f;
String strfloatConverasation = "HELLO";
tv.setText(String.format(Locale.ENGLISH,"%s %f %s",
res.getString(R.string.conversation), floatConverasation, strfloatConverasation));
可以通过将字符串传递到资源中来实现,即 getResources().getString(R.string.yourStringName)
您可以按照以下方式进行操作:
tv.setText(getText(R.string.Conversation)+" Hello");
尝试相同
tv.setText(getString(R.string.Converasation)+" Hello ");