其他分享
首页 > 其他分享> > android-MonoDroid onClick从XML没有这样的方法错误

android-MonoDroid onClick从XML没有这样的方法错误

作者:互联网

LiftInspection.axml

<Button
      android:id="@+id/expandCollapse1"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"          
      android:drawableLeft="@drawable/expand_arrow"
      android:text="Function/Controls"
      android:textSize="20sp"
      android:textColor="@android:color/white"
      android:background="@drawable/expandCollapseButton"
      android:gravity="center"
      android:onClick="button_Click"/>

LiftInspection.cs

protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.LiftInspection);
    }

public void button_Click(View view)
    {
        Toast.MakeText(this, "Testing", ToastLength.Long).Show();           
    }

单击按钮后,应用程序崩溃并强制关闭.在Android日志中,我发现“ java.lang.IllegalStateException:在活动类cpecfieldapp.LiftInspection的id为’expandCollapse1’的视图类android.widget.Button上的活动类cpecfieldapp.LiftInspection中找不到方法button_Click(View)”

从xml设置click事件中发现的所有内容仅显示了我在做什么.将其放在XML中的android:onClick中,并具有一个公共void,其中唯一参数是实现该布局的活动中的View.我想念什么?

解决方法:

当前版本的Mono for Android不支持该功能.您可以参考this bug report以获得更多详细信息.

标签:xamarin-android,android
来源: https://codeday.me/bug/20191201/2081448.html