K
K
kykyllllka2016-03-14 14:14:22
Android
kykyllllka, 2016-03-14 14:14:22

setOnClickListener difference?

Describing the buttons through the switch case, the question was whether there is a difference between different implementations of the code?

/* Button.OnClickListener onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (button.getId()) {
                    case R.id.button:
                        if (bIcon) {
                            mySound = MediaPlayer.create(list2.this, R.raw.vsolo);
                            mySound.start();
                            button.setImageResource(R.drawable.tiltedyes);

                        } else {
                            mySound.reset();
                            button.setImageResource(R.drawable.tilted);
                        }
                        bIcon = !bIcon;
                        break;
                }
            }
        };

        button.setOnClickListener(onClickListener);*/

and
button.setOnClickListener(new View.OnClickListener() {
           @Override
            public void onClick(View v) {
                switch (button.getId()) {
                    case R.id.button:
                        if (bIcon) {
                            mySound = MediaPlayer.create(list2.this, R.raw.vsolo);
                            mySound.start();
                            button.setImageResource(R.drawable.tiltedyes);

                        } else {
                            mySound.reset();
                            button.setImageResource(R.drawable.tilted);
                        }
                        bIcon = !bIcon;
                        break;
                }
            }
        });

Is there a difference between them? Is there a certain advantage? Or does it matter?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tiberal, 2016-03-14
@kykyllllka

no difference. in the first case, an extra link to the listener appears

K
kykyllllka, 2016-03-14
@kykyllllka

Thank you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question