0

I have a long text in TextView like "Hello How Are You \nThis Is my 'Second Activity'.". I want to make only 'Second Activity' text to clickable.

I am using TextView in ScrollView Like this:

<ScrollView android:id="@+id/scrollView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/gold_btn" android:orientation="vertical"><TextView android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#FFEFFF" android:text="" android:textSize="23sp"/></ScrollView>

and setting text in code using text1.setText("Hello How Are You This Is my Second Activity"); and i want to make "Second Activity" text to clickable and when user click on "Second Activity" text than another activity will open.

String is very long and have new lines also.

Md Mohsin
  • 1,568
  • 1
  • 18
  • 28
  • What have you thought till now? Have you tried breaking the problem into parts and searching solution of each part individually ? Eg: Making text clickable ; Start an activity from clickable text etc.. etc ? – Shobhit Puri Aug 29 '13 at 14:35
  • yes i have tried but did not get solution. – Md Mohsin Aug 29 '13 at 14:40
  • make SecondActivity static; or dynamically add another textview with the clickable text and add a click listener to it. – Rachit Mishra Aug 29 '13 at 14:46
  • i am making an app in which i am setting text in textView dynamically. There are 6 buttons and every button is setting some text in textview in new single activity. I want that if i press third button than this will generate some long string with new lines and the last string is "simple intrest" so i want the last string "simple interest" will become clickable. – Md Mohsin Aug 29 '13 at 15:00

2 Answers2

1

You should consider using ClickableSpan

Youll find something similar here.

How to set the part of the text view is clickable

Community
  • 1
  • 1
Yash Mehta
  • 46
  • 2
0

Add multiple textviews and put onclick to the textview that you want to click:

<TextView
    android:id="@+id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text=""
    android:textColor="#FFEFFF"
    android:textSize="23sp"
    android:onClick="doSomething"
     />

helpful link

Community
  • 1
  • 1
Dyna
  • 2,304
  • 1
  • 14
  • 25