jace jace - 4 years ago 136
Android Question

2 source of SetOnClickListener in c#

how can I determine from which source onClick of IOnClickListener is triggered?

I have this initialization of SetOnClickListener

private void setUpListener()
{
changePassword.SetOnClickListener(this);
forgotPassword.SetOnClickListener(this);
}


what i want to happen is

public void OnClick(View v)
{
if(source == changePassword)
{
Intent intent = new Intent(this, typeof(ChangePassword));
StartActivity(intent);
}
else if(source == forgotPassword)
{
Intent intent = new Intent(this, typeof(ForgotPassword));
StartActivity(intent);
}
}

Answer Source

In your OnClick method, put a switch case with the View v and specify the cases with the specific id assigned to the said views.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download