Android Studio XML 错误 "Corresponding method handler not found"onClick

标签 android android-layout android-studio kotlin

为什么在以 XML 命名 onClick 并在 Main Activity 上调用它之后,在 XML onClick 行上出现错误“未找到相应的方法处理程序”?

来自 activity_main.xml 的 fragment :

        <Button
            android:id="@+id/buPercentage"
            android:layout_width="30pt"
            android:layout_height="30pt"
            android:layout_weight="1"
            android:background="@color/lightgray"
            android:onClick="buPercentageEvent" //Error says Corresponding method handler not found
            android:text="%"
            android:textSize="18sp" />

来自 MainActivity.kt 的 fragment

fun buPercentageEvent()
{
    val convertToDecimal = displayText.text.toString()
    val newNumber = convertToDecimal.toDouble() / 100
    displayText.setText(newNumber.toString())
}

最佳答案

这样做

fun test(view: View){
        Log.e("Click","Yes")
    }

这会起作用。

关于Android Studio XML 错误 "Corresponding method handler not found"onClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44917962/

相关文章:

android - 如何正确布局这个 Fragment

android - 如何在 Android Studio 中使用 Cursive 构建 Android 应用

android - 如何解决 Cannot load project : java. lang.RuntimeException : java. io.EOFException while opening previous projects

java - 哪个更容易编码 : Android App vs iOS App?

android - BroadcastReceiver 监控连接的特定 USB 设备

android - 出于图形原因在 Android 中使用支持库

android - Butterknife 如何从不同的 View 绑定(bind) View

android - Datepicker 和 Timepicker 文本不出现在 Android 5.1.1

android - 下载适用于型号为 GT-P51110 的三星平板电脑的 OEM USB 驱动程序

android - 无法让RelativeLayout在Listview中工作