[英]How to add the text in String passed from another activity and show the resulting text in Textview
I am passing value from Activity A
to Activity B
.我正在将值从Activity A
传递到Activity B
。 It works fine.它工作正常。
For Example, if I pass String "Harvey Brown"
, Then in next activity it also shows "Harvey Brown"
.例如,如果我传递 String "Harvey Brown"
,那么在下一个活动中它也会显示"Harvey Brown"
。
But I would also like to add "Author: "
text before "Harvey Brown"
and show the sum result in TextView
such that now instead of only "Harvey Brown"
.但我还想在"Harvey Brown"
之前添加"Author: "
文本并在TextView
显示总和结果,这样现在而不是只有"Harvey Brown"
。
It will show它会显示
Author:Harvey Brown
for every intent.对于每个意图。
Here is the code, I'm using to pass String value:这是代码,我用来传递字符串值:
intent.putExtra("Title",mData.get(position).getTitle());
and in next activity I received value by在接下来的活动中,我收到了价值
Intent intent = getIntent();
String author_name = intent.getExtras().getString("author_name");
and I set the value accordingly as我相应地将值设置为
author_name = (TextView) findViewById(R.id.author_nameid);
author_name.setText(author_name);
Solution:解决方案:
Just change this line:只需更改这一行:
intent.putExtra("Title",mData.get(position).getTitle());
To到
intent.putExtra("Title", "Author: " + mData.get(position).getTitle());
You will get your desired result.你会得到你想要的结果。
You can add a 'Author:' Prefix like below -您可以添加“作者:”前缀,如下所示 -
author_name = (TextView) findViewById(R.id.author_nameid);
author_name.setText("Author: " + author_name);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.