Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java OnClick()方法不使用';不能在文本视图中工作_Java_Android_Android Layout_Navigation_Textview - Fatal编程技术网

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" />