user9468671
user9468671

Reputation: 9

How to set a multiple OnClickListeners in Android

How to set a multiple OnCLickListener in Android?

If I try to do it by using setOnClickListener, only the last one get called:

button.setOnClickListener(l1);
button.setOnClickListener(l2);

Upvotes: 0

Views: 52

Answers (1)

LukeWaggoner
LukeWaggoner

Reputation: 8909

Your best bet would be to take a good look at your code and refactor it to avoid needing to do this.

But if you must, I would call both of the actions you're wanting to trigger within one implementation.

Like this:

button.setOnClickListener(new View.OnClickListener(){
    @Overrride
    public void onClick(View view){
        actionOne();
        actionTwo();
    }
});

Upvotes: 1

Related Questions