0

I am trying to pass a string from one activity to another. I retrieved the information like this:

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

Now I want to display this string on screen. I this xml TextView element:

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

but I can't convert the string to a textview, is there a better way of doing this? thanks for your help guys!

1
  • One observation, your TextView should have a layout_height="" attribute as well, otherwise you may get an exception. Commented Oct 7, 2012 at 16:33

2 Answers 2

2

You have to create a variable for your TextView and then set the text.

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

Fromtxt.setText(readfrom);
Sign up to request clarification or add additional context in comments.

Comments

2

You need to set the text of the TextView with the String you read in.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.