1

I am trying to create a Share button that once the user presses will allow the user to share to a social networking site.

I have a textview with the text "Chipotle" in my xml and would like the text "Chipotle" to appear in my String Intent. So for example, if the user was to post it onto Facebook it would display "Hey I'm going to Chipotle" and will allow the user to post this onto their wall.

I have done so far this:

placeName = (TextView) findViewById(R.id.place_text);
placeName.getText().toString();
String eShare = "Hey I'm going to" + placeName;

With this I get the following

 I'm going to android.widget.TextView{123212432423....app:id/place_text)

Thanks in advance

4 Answers 4

1

You have to assign a variable to this line

placeName.getText().toString();

Like this

placeName = (TextView) findViewById(R.id.place_text);
String placeNameString = placeName.getText().toString();
String eShare = "Hey I'm going to" + placeNameString;
1
  • I see what I did wrong there. Thanks for your help :)
    – hung
    Nov 19, 2014 at 16:13
1

You are not grabbing the text from your textview. It'll work this way:

placeName = (TextView) findViewById(R.id.place_text);
String eShare = "Hey I'm going to " + placeName.getText().toString();
1
  • thanks :) this method also works as well as Marko's.
    – hung
    Nov 19, 2014 at 16:15
0

Try using String class as follows

placeName=(TextView) findViewById(R.id.place_text);
String str=placeName.getText().toString();
String eShare="Hey! I am going to "+str;

This will give the desired result ;-)

0

You need to use .getText().toString() in your assignment too. If you like it in one row:

String eShare = "Hey I'm going to " +
    ((TextView)findViewById(R.id.place_text)).getText().toString();

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.