Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Problem to set a OnClickListener

$
0
0

Hi everyone, I am new to Xamarin, I have a problem. Here are my codes:

using System;

using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS;

namespace Music_Exchanger { [Activity(Label = "Music Exchanger", MainLauncher = true, Icon = "@drawable/icon")] public class Activity1 : Activity {

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);
        Button Send_Button = FindViewById<Button>(Resource.Id.Send_Button);
        Send_Button.SetOnClickListener(this);


    }
    public override void OnClick(View V)
    { 
    //do sth...

    }
}

}

I receive an error: Error 1 'Music_Exchanger.Activity1.OnClick(Android.Views.View)': no suitable method found to override

In java, it works

package com.example.xxxxx;

import android.os.Bundle; import android.app.Activity; import android.view.*; import android.view.View.OnClickListener; import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener

{

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button mybutton=(Button)findViewById(R.id.button1);
    mybutton.setOnClickListener(this);

}


@Override
public void onClick(View V) {


}

}

I don't know why. What is the correct way to do it?? If you know, please tell me, thanks!


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>