Try this, in your our create method of the Activity, Give the reference of
your button listener.



findViewById(R.id.horizontallistview).setOnClickListener(this);
findViewById(R.id.search).setOnClickListener(this);
findViewById(R.id.facebook).setOnClickListener(this);
findViewById(R.id.twitter).setOnClickListener(this);

And Below is your onclick.

Note for you.

1st. Make sure the buttons which are using in this Activity is the part of
the view or xml

2n.Make sure your Activity class implements OnClickListener


@Override
public void onClick(View v) {
 switch (v.getId()) {

case R.id.horizontallistview:

 Toast.makeText(this, "On  horizontallistview ",Toast.LENGTH_LONG).show();

break;

case R.id.search:
 Toast.makeText(this, "On Search",Toast.LENGTH_LONG).show();

break;

case R.id.facebook:
 Toast.makeText(this, "On   facebook ",Toast.LENGTH_LONG).show();
break;

case R.id.twitter:
            Toast.makeText(this, "On   twitter ",Toast.LENGTH_LONG).show();
break;

default:
break;
}
}

Warm Regards,
*Mukesh Kumar*,
Android Consultant/Freelancer,
India,Hyderabad.

On Sun, Jan 1, 2012 at 5:38 AM, Daniel <[email protected]> wrote:

> I'm trying to make a single onClickListener for several views. I have
> successfully done this for buttons that do the same thing (such as
> change the background image of the button clicked), but I want to be
> able to refer to what button has been pressed for some actions within
> the onClick() method. My understanding of views suggested that
> R.id.myClickedView should equal view.getId() inside of the onClick()
> method, but my
>
> if(R.id.myClickedView == view.getId()) {   }
>
> loop is never entered, and the debugger shows these two values to be
> different.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




--

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to