18

I want to create a TextView in my first Activity as a link, when i click on that textview i want to start the second activity in my application.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
sathish
  • 285
  • 1
  • 7
  • 11

3 Answers3

28

Implement a View.OnClickListener for your TextView and start the other activity in the listener:

textView.setOnClickListener(new View.OnClickListener(){
       public void onClick(View v){
             Intent intent = new Intent(this, OtherActivity.class);
             startActivity(intent);
       }
});
GuilhE
  • 11,591
  • 16
  • 75
  • 116
codinguser
  • 5,562
  • 2
  • 33
  • 40
  • Also, if you wish to change the background color of the TextView upon click so as to give the user visual feedback, see this question http://stackoverflow.com/questions/4336218/android-textview-change-color-on-changing-of-state – codinguser May 05 '11 at 12:42
  • Hi codinguser, thanks for your help, it works fine, but initially i need to display the text as link means show the text with underline and color in blue, then after clicking on the text i need to change the text color to red and opens new activity. is there any other possibility? – sathish May 05 '11 at 12:59
  • 3
    I would suggest just formatting the text to blue and adding an underline. since you are starting an Activity, then it does not seem to matter that the link should be actually pointing to a URL. Use normal html to style the text and then call `textView.setText(Html.fromHtml("your text here"));` – codinguser May 05 '11 at 13:10
  • codinguser, i got some suitable solutions for my requirement in this [link](http://stackoverflow.com/questions/3822065/how-to-create-textview-that-will-act-as-a-link) , in this i created TextView with `autolink = all`, it is working fine for me. – sathish May 05 '11 at 14:08
2

i got some suitable solutions for my requirement in this Link , in this i created TextView with autolink = all, it is working fine for me.

Community
  • 1
  • 1
sathish
  • 285
  • 1
  • 7
  • 11
1

Use textView.setOnClickListener() (View.OnClickListener) to start new activity, please refer to the documentation.

MByD
  • 135,866
  • 28
  • 264
  • 277