Java OnClick()方法不使用';不能在文本视图中工作
我有一个Java OnClick()方法不使用';不能在文本视图中工作,java,android,android-layout,navigation,textview,Java,Android,Android Layout,Navigation,Textview,我有一个textView和OnClick方法来导航另一个活动。但是,如果我按下该文本,它将无法导航。但是如果我使用按钮而不是TextView,它工作得非常好。无法在TextView中使用OnClick方法 我的XML代码 <TextView android:onClick="webClick" android:layout_width="wrap_content" android:layout_height="wrap_content" android:la
textView
和OnClick
方法来导航另一个活动。但是,如果我按下该文本,它将无法导航。但是如果我使用按钮
而不是TextView
,它工作得非常好。无法在TextView
中使用OnClick
方法
我的XML代码
<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" />
尝试添加
android:clickable=“true”
将此属性添加到textview
android:clickable="true"
android:clickable
定义此视图是否对单击事件作出反应。
必须是布尔值,为“真”或“假”。
这也可能是对包含此类型值的资源(格式为“@[package:]type:name”)或主题属性(格式为“?[package:][type:]name”)的引用
这对应于可单击的全局属性资源符号
相关方法
可设置可点击(布尔)只需将代码替换为
<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" />
添加此属性android:clickable=“true”
很好。它的作品。谢谢加上这个作为答案。我将对此进行标记。将评论作为答案发布。@MohamedThaufeeq我知道这是论坛规则。谢谢。@Raghunandan你能帮我吗
android:clickable="true"
<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" />