2012-10-07 54 views
0

我想从一个活动传递一个字符串到另一个。我获得的信息是这样的:android显示字符串

Intent openReadMail = getIntent(); 
String readfrom = openReadMail.getStringExtra("from"); 

现在我想在屏幕上显示此字符串。我这个XML TextView元素:

<TextView 
     android:id="@+id/from" 
     android:layout_width="match_parent"/> 

,但我不能将字符串转换为一个TextView,是有这样做的更好的办法?感谢您的帮助!

+0

一观察,你的'TextView'应该有一个'layout_height =“”'属性为好,否则你可能会得到一个例外。 –

回答

2

您必须为您的TextView创建一个变量,然后设置文本。

TextView fromtxt = (TextView) findViewById(R.Id.from); 

Fromtxt.setText(readfrom); 
2

您需要设置与您在读取字符串TextView的文本。

TextView tv = (TextView)findViewById(R.id.from); 
tv.setText(readFrom); 
+0

谢谢你们,非常感谢! – shanahobo86