Reputation: 881
Im very new at this and I really searched for the answer. I know this question will be very easy, but I really need help.
I have multiple ImageButton
s, but dont know how I make different OnClicklistener
for them.
This is my code, and I think something is missing here.
ImageButton facebookButton = (ImageButton) findViewById(R.id.imageButtonFacebook);
ImageButton twitterButton = (ImageButton) findViewById(R.id.imageButtonTwitter);
facebookButton.setOnClickListener(new View.OnClickListener() {
twitterButton.setOnClickListener(new View.OnClickListener() {
}
})
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.imageButtonFacebook:
Intent fb = new Intent (MainActivity.this, FacebookActivity.class);
startActivity(fb);
break;
case R.id.imageButtonTwitter:
Intent tw = new Intent (MainActivity.this, TwitterActivity.class);
startActivity(tw);
break;
What is the problem?
Upvotes: 2
Views: 796
Reputation: 72533
Implement View.OnClickListener
:
public class MyClass extends Activity implements OnClickListener {...}
and then set the OnClickListeners
like this:
facebookButton.setOnClickListener(this);
twitterButton.setOnClickListener(this);
Upvotes: 2