Android Studio XML error “Corresponding method handler not found” on onClick

好久不见. 提交于 2020-01-24 09:48:06

问题


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?

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" />

Snippet from MainActivity.kt

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

回答1:


Do this

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

This will work.



来源:https://stackoverflow.com/questions/44917962/android-studio-xml-error-corresponding-method-handler-not-found-on-onclick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!