9

I would like to add button myButton to TextView. How to get it in a single line so that it looks like one set of lines. Here is sample of the text to be added

Please press this here to refresh the set of values.

I want to have "here" as clickable button. How can I do it. Any snippet on it would be helpful.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Karthik
  • 4,943
  • 19
  • 53
  • 86
  • duplicate question: http://stackoverflow.com/questions/3328757/how-to-click-or-tap-on-a-textview-text – PC. Jan 31 '12 at 09:17
  • You can try some of these approaches: http://stackoverflow.com/questions/1697084/handle-textview-link-click-in-my-android-app – Vikram Bodicherla Jan 31 '12 at 09:19

5 Answers5

14

Set background of Button as null by android:background="@null" give the same text color as given to other TextView's.

or You can take 3 TextView's and setOnClickListener to middle one.

Arun Badole
  • 10,977
  • 19
  • 67
  • 96
12

Set style of Button with borderless android attribut to remove background and border:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="?android:attr/borderlessButtonStyle"
    android:text="here" />
J. Gobet
  • 179
  • 1
  • 5
3

make three textView ex: textView1, textView2 and textView3.

<RelativeLayout android:id="@+id/textLay"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    >

    <TextView android:id="@+id/textView1" android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="Please press this"/>

    <TextView android:id="@+id/textView2" android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
         android:text="here" 
        android:layout_toRightOf="@+id/textView1"  />

    <TextView android:id="@+id/textView3" android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
         android:text="to refresh the set of values." 
        android:layout_toRightOf="@+id/textView2"  />

</RelativeLayout>
helloDroid
  • 654
  • 1
  • 6
  • 14
  • 3
    This doesnt comes well when we take into multi line text.How to solve it in due with modifying the snippet. – Karthik Jan 31 '12 at 08:58
3

Just add below attribute to TextView in XML layout file to make it clickable.

android:clickable="true"

In your Java file add OnClickListener to complete click action on text view.

Yugandhar Babu
  • 10,311
  • 9
  • 42
  • 67
2

Add android:clickable="true" and android:onClick="yourclickname" for the TextView in the XML. Then define yourclickname in your activity. This should make your TextView clickable and triggers the specified method when clicked.

Mangesh
  • 5,491
  • 5
  • 48
  • 71
Shruti Dasgopal
  • 551
  • 4
  • 10