-2

To set text as a link i followed this [How do I make links in a TextView clickable?

But when i click on that text it should pass that text to another activity . How to do that.

For example i have set few text in one activity as links , so when i click on that link it should go to another activity and even that text data should be passed.

Please somebody help me with it. I am new to android development.

Community
  • 1
  • 1
Naveen Kumar
  • 979
  • 1
  • 13
  • 24
  • Are you referring to text link rendered via webview or you have a text in a label and would want to click a button and then have the text launch another activity and transferred to that new activity? – Yaojin May 05 '14 at 05:55

2 Answers2

0

Its very simple just define this under you onclick functionality where you intent to next activity

Define Onclick like this under OnCREATE

  YourTEXT.setOnClickListener(new View.OnClickListener() 
    {
            @Override
            public void onClick(View v) 
            {
                 next();
            }

        });

Then write this function anywhere in your activity

    public void next()
   {

  String strMessage = YourTEXT.getText().toString());

// so on you can directly set values
// you have to just set values in string                      

  Intent i = new Intent(getApplicationContext(), nextactivity.class)   
  i.putExtra("new_variable_name",strMessage);


  startActivity(i);  

}

Then in your next activity retrieve it via

Bundle extras = getIntent().getExtras();
String var="";

      if (extras != null)
      {

        String value= extras.getString("new_variable_name");       
        value= var;

      }

Then you can use the string var in your next activity

Tushar Narang
  • 1,997
  • 3
  • 21
  • 49
0

When you use Linkify to add links to text, pass in a scheme with something like below:

private static void linkifyUsername(TextView text){
    Pattern pattern = Pattern.compile("@([a-zA-Z]|[\u4E00-\u9FA5]|[0-9]|_|-)+");
    String scheme = "com.example.app.profile://";
    Linkify.addLinks(text, pattern, scheme);
}

in your AndroidManifest.xml, put in an intent-filter as below for the activity which will accept that link (use the same scheme):

<activity android:name=".Profile" android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden"
android:screenOrientation="portrait">
    <intent-filter>
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="com.example.app.profile" />
    </intent-filter>
</activity>

now clicking on the link in the text will lead to the Profile activity, in Profile activity you can use code below to retrieve the link:

Uri data = getIntent().getData();
OatsMantou
  • 193
  • 3
  • 7