LiftInspection.axmlMonoDroid的的onClick從XML沒有這樣的方法錯誤
<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:無法找到一個方法button_Click(視圖)在活動類cpecfieldapp.LiftInspection onClick處理器視圖類android.widget.Button與id'expandCollapse1'」
我從xml中找到的設置點擊事件的所有內容都只顯示我在做什麼。將它放在android:onClick中,並且有一個公共的void,其中唯一的參數是實現該佈局的活動中的View。我錯過了什麼?
即將4.1.0 alpha版本將支持此方案。 – jonp 2012-04-03 19:04:19
4.10.2中沒有工作,仍然與OP相同。 – 2014-02-07 03:08:08