【问题标题】:Android Studio XML error "Corresponding method handler not found" on onClickonClick 上的 Android Studio XML 错误“找不到相应的方法处理程序”
【发布时间】:2017-12-08 15:13:34
【问题描述】:

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

来自activity_main.xml 的片段:

        <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 的片段

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

【问题讨论】:

    标签: android android-layout android-studio kotlin


    【解决方案1】:

    这样做

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

    这会起作用。

    【讨论】:

    • 非常感谢!介意简单解释一下吗?
    • 没什么好解释的,你必须在参数中传递视图,如果可行,请接受答案。
    • @Sinistro 点击答案向上/向下图标下方的右侧图标,如果它对你有用
    • @RavindraKushwaha 不明白?
    • 什么? ..我只是对提问者说,如果它对你有用,请接受答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-25
    相关资源
    最近更新 更多