android - ImageView will not update when touched. "res cannot be resolved" -
playbutton.setontouchlistener(new ontouchlistener() { @override public boolean ontouch(view arg0, motionevent arg1) { switch(arg1.getaction()) { case motionevent.action_down: { playbutton.setimagebitmap(res.getdrawable(r.drawable.play_pushed)); break; } case motionevent.action_cancel: { playbutton.setimagebitmap(res.getdrawable(r.drawable.play)); break; } } return true; } });
the 2 res keywords underlined in red. trying change image darker version of when touched. necessary images located in res folder. idea problem is?
update: updated code little , works perfectly:
playbutton.setontouchlistener(new ontouchlistener() { @override public boolean ontouch(view arg0, motionevent arg1) { switch(arg1.getaction()) { case motionevent.action_down: { playbutton.setimagedrawable(getresources().getdrawable(r.drawable.play_pushed)); break; } case motionevent.action_up: { playbutton.setimagedrawable(getresources().getdrawable(r.drawable.play)); break; } } return true; } });
try changeing them
getresources().getdrawable(...)
since inside of listener may need activityname.this.getresources().getdrawable()
playbutton.setimagebitmap(getresources().getdrawable(r.drawable.play_pushed));
res
folder name isn't variable have declared system doesn't know is.
Comments
Post a Comment