2012-04-03 2 views
3

LiftInspection.axmlMonoDroid의 onclick 그런 방법 오류

<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();   
    } 

. 안드로이드 로그에서 "java.lang.IllegalStateException : id_expandCollapse1 '을 사용하는 android.widget.Button 뷰 클래스의 onClick 핸들러에 대한 cpecfieldapp.LiftInspection 활동 클래스에서 button_Click (View) 메서드를 찾을 수 없음"

xml에서 클릭 이벤트를 설정할 때 발견 한 모든 것만 내가하는 일을 보여줍니다. android : onClick을 XML에서 가져 와서 유일한 매개 변수가 해당 레이아웃을 구현하는 액티비티의 뷰인 public void를 갖는 것. 내가 뭘 놓치고 있니?

답변

3

Android 용 Mono의 현재 버전에서는 지원되지 않습니다. 이에 대한 자세한 내용은 this bug report을 참조하십시오.

+1

살아갈 4.1.0 알파 버전이 시나리오를 지원합니다. – jonp

+0

4.10.2에서 작동하지 않으며 OP와 동일한 문제가 발생합니다. –

0

button_Click 메서드에 [Export] 특성을 추가하여 작동하도록했습니다.

0

이제 가능합니다. 당신은 세 가지를 수행해야합니다 같은

  1. 참조 Mono.Android.Export
  2. using Java.Interop
  3. 주석 이벤트 방법 :
[Export ("button_Click")] 
public void button_Click(View view) 
    { 
     Toast.MakeText(this, "Testing", ToastLength.Long).Show();    
    }