i want change images in image view on onclick
function. have tried this:
bt_audiocapture.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { if (checkpermission()) { if (bt_audiocapture.getresources().getdrawable(r.drawable.ic_mic).equals(r.drawable.ic_mic)) { start(); bt_audiocapture.setimageresource(r.drawable.ic_stop); } else if (bt_audiocapture.getresources().getdrawable(r.drawable.ic_stop).equals(r.drawable.ic_stop)) { stop(); bt_audiocapture.setimageresource(r.drawable.ic_play); } else if (bt_audiocapture.getresources().getdrawable(r.drawable.ic_play).equals(r.drawable.ic_play)) { play(); } } } });
bt_audiocapture.getresources().getdrawable(r.drawable.ic_mic)
returns drawable
object. can't compare r.drawable.ic_mic
, integer
. comparing car
green color
.
to accomplish task, make field private int state = 0;
, , constants
private final state_playing = 1; private final state_stopped = 2; private final state_none = 0;
and then:
if (state == state_none) { start(); bt_audiocapture.setimageresource(r.drawable.ic_stop); state = state_playing; } else if (state == state_playing) { stop(); bt_audiocapture.setimageresource(r.drawable.ic_play); state = state_stopped; } else if (state == stopped) { play(); state = state_playing; }
Comments
Post a Comment