【问题标题】:Application crashes when trying to set OnClick for button尝试为按钮设置 OnClick 时应用程序崩溃
【发布时间】:2015-09-20 04:32:48
【问题描述】:

我是 Android Studio 新手,正在尝试使用 XML 为按钮设置 OnClick 侦听器。我使用了 android:onClick 但是当我运行应用程序并按下按钮时它崩溃了。

这是我的 XML:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Convert"
    android:id="@+id/convertButton"
    android:onClick="onConvertButtonClicked(View v)"
    android:layout_below="@+id/radioGroup"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="49dp"/>

这是我的 java 代码的样子:

public void onConvertButtonClicked(View v){...}

【问题讨论】:

    标签: button android-studio onclick


    【解决方案1】:

    在 XML 中输入不带括号或参数的方法名称 {android:onClick="onConvertButtonClicked"}

    【讨论】:

      猜你喜欢
      • 2020-07-25
      • 1970-01-01
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多