【发布时间】:2012-04-17 08:18:55
【问题描述】:
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:在 id'expandCollapse1' 的视图类 android.widget.Button 上的 onClick 处理程序的活动类 cpecfieldapp.LiftInspection 中找不到方法 button_Click(View)”
我在从 xml 设置点击事件时发现的所有内容都只显示了我在做什么。将其放入 XML 中的 android:onClick 并具有公共 void,其中唯一的参数是实现该布局的 Activity 中的 View。我错过了什么?
【问题讨论】: