Android:onClick事件监听器不适用于linearlayout

Henry Zhu

我正在尝试为整个布局实施onclick,但是它将无法正常工作。

这是我的RelativeLayout的函数:

public void updateRange(View v)
{
    System.out.println("Hello!");
}

这是我的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".MainActivity"
    android:background="#ffffffff"
    android:id="@+id/xasdf"
    android:onClick="updateRange">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/toptab"
        android:orientation="horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Settings"
            android:fontFamily="monospace"
            android:textAllCaps="false"
            android:layout_weight="0.333333"
            android:id="@+id/settingsButton"
            android:background="#fffdb64b" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Solutions"
            android:fontFamily="monospace"
            android:textAllCaps="false"
            android:layout_weight="0.333333"
            android:id="@+id/solutionsButton"
            android:background="#fffdb64b" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Mode"
            android:fontFamily="monospace"
            android:textAllCaps="false"
            android:layout_weight="0.333333"
            android:id="@+id/modeButton"
            android:background="#fffdb64b" />

    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:gravity="center_vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/chartlayout"
        android:layout_below="@+id/toptab"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:weightSum="1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/textView"
            android:layout_weight="0.5"
            android:background="#ffffffff"
            android:fontFamily="monospace"
            android:hint="y = ..." />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Graph"
            android:fontFamily="monospace"
            android:textAllCaps="false"
            android:layout_weight="0.25"
            android:id="@+id/button"
            android:background="#ffd0d0d0"
            android:onClick="drawGraph" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Table"
            android:fontFamily="monospace"
            android:layout_weight="0.25"
            android:textAllCaps="false"
            android:id="@+id/button2"
            android:background="#ffd0d0d0" />
    </LinearLayout>

</RelativeLayout>
数字忍者

尝试在您的Relative Layout描述中添加以下额外的行

...
android:onClick="updateRange"
android:clickable="true">

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

点击事件监听器不适用于VueJS中的组件

来自分类Dev

onClick事件不适用于Android

来自分类Dev

如何创建适用于事件监听器标记的元素ID的函数?

来自分类Dev

如何创建适用于由事件监听器标记的元素ID的函数?

来自分类Dev

onclick事件不适用于选项

来自分类Dev

QuerySelectorAll不适用于onclick事件

来自分类Dev

为左或右键单击附加事件侦听器-onclick不适用于右键单击

来自分类Dev

MapView onCLick事件监听器

来自分类Dev

停止事件冒泡 - onclick 监听器

来自分类Dev

jQuery onclick事件不适用于td

来自分类Dev

href链接不适用于Safari中的onclick事件

来自分类Dev

onclick事件不适用于position:fixed

来自分类Dev

onclick事件不适用于多种功能

来自分类Dev

onclick事件不适用于替换的片段

来自分类Dev

Onclick事件不适用于提交类型按钮

来自分类Dev

HTML 5模式不适用于按钮的onclick事件

来自分类Dev

onclick事件不适用于svg元素

来自分类Dev

多个 OnClick 事件不适用于所有对象

来自分类Dev

Android事件总线不适用于两个事件侦听器

来自分类Dev

是否有适用于JavaSE的WebSocket消息监听器?

来自分类Dev

高程不适用于LinearLayout

来自分类Dev

事件侦听器不适用于锚点

来自分类Dev

悬停事件不适用于 :not 选择器

来自分类Dev

DialogFragment onClick侦听器不适用于ImageButton

来自分类Dev

OnClick()不适用于货币转换器。

来自分类Dev

Android片段事件监听器

来自分类Dev

Android片段事件监听器

来自分类Dev

事件侦听器无法正常工作,适用于 chrome,不适用于 Firefox

来自分类Dev

在onclick中附加click事件监听器会立即调用该事件监听器

Related 相关文章

热门标签

归档