Android imagebutton change on every click
I want my imagebutton's to change from one image to another image every
time its clicked. In my code this only works once, the image changes and
the button will not change back onClick.
Can someone help?
package com.wepromoteme.brapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupPlayPauseButton1();
}
private void setupPlayPauseButton1() {
ImageButton btn1 = (ImageButton) findViewById(R.id.play_pause1);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ImageButton btn1 = (ImageButton)
findViewById(R.id.play_pause1);
btn1.setImageResource(R.drawable.play);
}
});
}
}
Thanks
No comments:
Post a Comment