Could not find method XXXX(View ) in a parent or ancester Context for android:onClick attribute

1.xml中的按钮代码详情如下:

<Button
        android:text="是否开启"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button2"
        android:onClick="isBlueToothEnable (MainActivity)" />

2.Acivity中“isBlueToothEnable”点击方法如下:

public void isBlueToothEnable(View view){
        boolean ret = mcontroller.getBlueToothStatus();
        showToast("是否打开了蓝牙?"+ret);
    }

3.解决方法是对xml中的内容进行修改:
修改前:

android:onClick="isBlueToothEnable (MainActivity)" />

修改后:

android:onClick="isBlueToothEnable" />

4.重新编译运行,问题解决。

猜你喜欢

转载自blog.csdn.net/weiybin/article/details/130322873