问题
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