OnClick event getting fired twice

PareshSukhiyaPareshSukhiya USMember ✭✭
edited March 2018 in Xamarin.Android
<Button
        android:id="@+id/inc"
        android:text="inc"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_marginTop="10dp"
        android:textStyle="normal"
        android:layout_toLeftOf="@id/btnDel"
        android:layout_marginRight="10dp"
        android:textSize="05dp"
        android:clickable="true" />

This my code for the button
and I call it in my ViewAdapter using below code

Button increment = view.FindViewById<Button>(Resource.Id.inc);
             increment.Click += delegate
            {
            //Here Goes My Code

        };

But when I click on the button then the event get fired twice due to which the code runs twice
please Help! Thanks in Advance

Best Answer

Answers

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭

    Hello @paraszalariya
    in your view adapter INHERIT from
    View.IOnClickListener

    on method getView do this
    yourButton.SetOnClickListener(this);
    add last implement interface onclick

    i hope this solve your problem
    I have a listview with just a button delete and when i click on button the call is made just one time

  • PareshSukhiyaPareshSukhiya USMember ✭✭

    @ChristopheBERNARD I didn't get you!
    Can you Please ellaborate
    Many Thanks!

  • PareshSukhiyaPareshSukhiya USMember ✭✭
    edited March 2018

    Thanks A Ton! @ChristopheBERNARD

  • PareshSukhiyaPareshSukhiya USMember ✭✭

    @ChristopheBERNARD
    But I have say around 5-6 buttons in this adapter those have onclick events
    So do I need to have Seperate Classes for each Onclick Event?

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭

    @PareshSukhiya
    in the onclick event you have the view with this you can determine witch button has been clicked
    `
    public void onClick(View v) {
    if (v.Id == Resource.Id.YOURBUTTON)

    `

  • PareshSukhiyaPareshSukhiya USMember ✭✭

    thanks once Again! @ChristopheBERNARD

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭

    don't mention it guy :)

Sign In or Register to comment.