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

comparing 2 drawables in android


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -