0
我只是想端口一些代碼我在原生Android/Java的寫信給MonoDroid的 - 但我得到當我點擊一個按鈕,出現以下錯誤:使用MonoDroid有沒有辦法用按鈕做DoClick()switch/case語句?
java.lang.IllegalStateException:找不到的方法DoClick(查看)在活動課icantalk.android.CreateProfile爲的onClick處理程序上的視圖類android.widget.Button ID爲 'createProfilePicBtn'
public void DoClick(View view)
{
switch (view.Id)
{
case Resource.Id.createProfilePicBtn:
{
Log.Error("Profile Pic", "Clicked");
break;
}
case Resource.Id.createProfileSbmtBtn:
{
Log.Error("Save Button", "Clicked");
break;
}
}
}
我的佈局XML的相關部分:
<Button
android:id="@+id/createProfilePicBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:onClick="DoClick"
android:text="@string/createProfileImgBtnTxt" />
<Button
android:id="@+id/createProfileSbmtBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:onClick="DoClick"
android:text="@string/createProfileSaveBtnTxt" />
尼斯和清潔。謝謝! – Kiada
Mono for Android 4.2值得注意,您現在可以導出「DoClick」方法,以允許從Axml調用此方法(請參閱http://docs.xamarin.com/android/Releases/Mono_For_Android_4/Mono_For_Android_4.2#有關更多信息,請參閱Exporting_arbitrary_Java_member_for_better_Java_integration) – chrisntr