我尝试了两种不同的方式来设置ImageButton的事件,但都没有奏效。一旦该按钮被点击ImageButton点击不起作用
private void infoButtonClick()
{
Console.Write("Clicked");
}
应用崩溃:首先,我试图在axml文件中添加的onClick:
<ImageButton
android:src="@drawable/homeInfoButtonImages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/homeInfoButton"
android:layout_marginLeft="200dp"
android:layout_marginTop="600dp"
android:background="@null"
android:onClick="infoButtonClick" />
在Activity.cs。
第二种方法我试过Activity.cs:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Home);
// Create your application here
ImageButton button = FindViewById<ImageButton>(Resource.Id.homeInfoButton);
button.Click += delegate
{
infoButtonClick();
};
}
private void infoButtonClick()
{
Console.Write("Clicked");
}
什么也没有发生按钮被点击时...
什么可能会造成这个问题?
你可以发布崩溃的logcat输出吗?我怀疑你没有添加[Java.Interop.Export(“infoButtonClick”)]作为你的infoButtonClick方法的一个属性。 看到这个相似的答案由我:http://stackoverflow.com/questions/20197848/xamarin-android-how-to-capture-button-events-defined-in-the-onclick-xml-attribu – matthewrdev