2

I'm using Caldroid and I have a problem with getting background color of clicked date. My listener looks like that:

listener = new CaldroidListener() {
    @Override
    public void onSelectDate(Date date, View view) {
        //HERE I WANT TO CHECK COLOR
    }
};

How can I check background color of clicked date in above listener?

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
AYMADA
  • 889
  • 3
  • 17
  • 37

1 Answers1

1

Try this,

ColorDrawable buttonColor = (ColorDrawable)view.getBackground()
int color = buttonColor.getColor();
if (color == android.R.color.white) {
    //color is white
}
Andrew T.
  • 4,701
  • 8
  • 43
  • 62
  • That does not work for me; I get a "java.lang.ClassCastException: android.graphics.drawable.StateListDrawable cannot be cast to android.graphics.drawable.ColorDrawable" – Running Turtle Sep 29 '14 at 16:09
  • May you use Dravable, not color for your background of view. Try check to instanceof: Drawable buttonColor = view.getBackground() if(buttonColor instanceof ColorDrawable){ ... } – user2969017 Nov 19 '14 at 11:56