3

I have a textView with OnClick method to navigate another activity. But, If i pressed that text it doesn't navigate. But If i used Button instead TextView, it works perfectly. Can't use OnClick method in TextView?

My XML Code;

<TextView
    android:onClick="webClick"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:layout_marginLeft="17dp"
    android:layout_marginTop="19dp"
    android:text="Chapter 1"
    android:textSize="25dp" />

My Java Code:

public void webClick(View v) {
    Intent intent = new Intent(this, Webview.class);
    startActivity(intent);
}
mmBs
  • 8,421
  • 6
  • 38
  • 46

3 Answers3

5

Add this attribute to textview

       android:clickable="true"

http://developer.android.com/reference/android/view/View.html#attr_android:clickable

android:clickable

Defines whether this view reacts to click events.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol clickable.

Related Methods setClickable(boolean)

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • @MohamedThaufeeq i understand that it is the forum rules. thanks. – Raghunandan Aug 05 '13 at 06:11
  • @Raghunandan can u help me on this http://stackoverflow.com/questions/18054704/how-to-use-scroll-view-in-android?noredirect=1#comment26421587_18054704 – Developer Aug 05 '13 at 13:08
0

try by adding android:clickable="true"

<TextView
    android:clickable="true"
    android:onClick="webClick"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:layout_marginLeft="17dp"
    android:layout_marginTop="19dp"
    android:text="Chapter 1"
    android:textSize="25dp" />
Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71
0

Just replace your code with this

<TextView
    android:id = "+@id/tvName"
    android:clickable="true"
    android:onClick="webClick"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:layout_marginLeft="17dp"
    android:layout_marginTop="19dp"
    android:text="Chapter 1"
    android:textSize="25dp" />
Sanket Shah
  • 4,352
  • 3
  • 21
  • 41