Answer the question
In order to leave comments, you need to log in
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);*/
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;
}
}
});
Answer the question
In order to leave comments, you need to log in
no difference. in the first case, an extra link to the listener appears
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question