android - Switching Image of Imageview using onClickListener -
i making music player app in there image of play button , once clicked switch pause.png , song start playing. clicking again on button change image play.png , pause sound. pattern continues.
this question has been answered first click change new image , second click change old image, android
but checked answer doesn't work because boolean variable used switch need declared final. , once declared final cannot change value of variable.
boolean showingfirst = true; //declare globally image1.setonclicklistener(new onclicklistener() { public void onclick(view v) { if(showingfirst){ image1.setimageresource(r.drawable.img1); showingfirst = false; }else{ image1.setimageresource(r.drawable.img2); showingfirst = true; } } });
Comments
Post a Comment