我的 android java 按钮出现并显示动画但由于某种原因我的代码从未执行

My android java button shows up and animates but for some reason my code is never executed

我的 android 应用程序中有一个按钮。

 <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Start scanning"
    android:id="@+id/bStartScan"
    android:enabled="true"
    android:clickable="true"
    android:layout_below="@+id/third_person_button"
    android:layout_toEndOf="@+id/StitchPCButton"
    android:longClickable="false" />

该按钮确实具有动画效果并且它确实显示在我的应用程序中,但是执行了下面的 none 代码。

public void onClick(View v) {
    switch (v.getId()) {
        case R.id.bStartScan:
            findViewById(R.id.bStartScan).setEnabled(false);
            ...
            ...
            break;
        default:
            Log.w(TAG, "Unrecognized button click.");
    }
}

我的其他按钮工作正常,我不明白为什么这个按钮拒绝触发。

有什么想法吗?有什么问题吗?

在此先感谢您。

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start scanning"
android:id="@+id/bStartScan"
android:layout_below="@+id/third_person_button"
android:layout_toEndOf="@+id/StitchPCButton"
/>

在你的activity/Fragment中使用这个 onCreate() 在

      Button startBtn = (Button) findViewById(R.id.bStartScan);
startBtn.setonClicklistner(this);

移除 findViewById(R.id.bStartScan) 来自 switch() 语句...

将此行添加到您的 xml 按钮代码中 -> android:onClick="onClick"

在您的 xml 按钮标签中添加此行:

android:onClick="myMethod"

并在 activity class 中添加如下方法:

public void myMethod(View v) 
{
  // write your code here
}