Question

Im trying my first steps with dot42.

I defined a Button like this:

  <Button android:id="@+string/button_send"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Senden"
        android:onClick="sendMessage"/>

I thought i could now define a method in the MainActivity Class like this:

 [Activity]
public class MainActivity : Activity
{
    protected override void OnCreate(Bundle savedInstance)
    {
        base.OnCreate(savedInstance);
        SetContentView(R.Layouts.MainLayout);
    }

    public void sendMessage(View view)
    {

    }
}

But unfortunately i get an Exception when clicking that button..

you find information about dot42 here

Was it helpful?

Solution

I received an answer on this by dot42 support:

You can fix this by adding an [EventHandler] attribute (from Dot42.EventHandlerAttribute) to the sendMessage method like this:

[EventHandler]
public void sendMessage(View view)
{
    Toast.MakeText(this, "Button pressed", Toast.LENGTH_LONG).Show();
}

This ensures that the sendMessage method is not renamed and included in the APK. dot42 will by default try to remove as much code as possible and since sendMessage is not referenced (from code) it will remove it. Adding the attribute prevents that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top