Android Studio XML错误“未找到对应的方法处理程序"在onClick [英] Android Studio XML error "Corresponding method handler not found" on onClick

查看:224
本文介绍了Android Studio XML错误“未找到对应的方法处理程序"在onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why do I get error "Corresponding method handler not found" on the XML onClick line, after naming the onClick in XML and calling it on Main Activity?

activity_main.xml中的代码段:

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

Snippet from MainActivity.kt

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错误“未找到对应的方法处理程序"在onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆