android - Get drawable of image button -
how can drawable of image button compare , if drawable , if b?. thank much.
switch(getdrawableid(buttonrepeat)) { case r.drawable.a: mediaplayer.setlooping(true); break; case r.drawable.b: mediaplayer.setlooping(false); break; default: break; }
use getdrawable()
method in imagebutton , compare them using .getconstantstate().equals()
sample code:
imagebutton btn = (imagebutton) findviewbyid(r.id.myimagebtn); drawable drawable = btn.getdrawable(); if (drawable.getconstantstate().equals(getresources().getdrawable(r.drawable.mydrawable).getconstantstate())){ //do work here }
references:
http://developer.android.com/reference/android/widget/imagebutton.html
Comments
Post a Comment