0

i have already seen many posts and many different ways to swtich between two different drawables but I always got ResourcesNotFoundException on this little piece of code :

 Drawable btn;
    if (sens.getAlarmCount() == 0)
        btn = view.getResources().getDrawable(R.drawable.chart_alarm_none);
    else
        btn = view.getResources().getDrawable(R.drawable.chart_alarm);      
    alarm.setBackgroundDrawable(btn);       
    alarm.setText(sens.getAlarmCount());

and my 2 drawbles xml files into drawable/ folder are same except gradient for alarmState:

<?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item> 
    <shape android:shape="rectangle">
      <solid android:color="#FFFFFF" /> 
      <corners android:bottomRightRadius="2dip"
               android:bottomLeftRadius="2dip"  
               android:topRightRadius="2dip"
               android:topLeftRadius="2dip"/>
    </shape>
  </item>   
    <item android:left="2dp" android:right="2dp"  android:top="2dp" android:bottom="2dp">  
     <shape android:shape="rectangle"> 
       <gradient
        android:startColor="#FF0000"
          android:endColor="#801818"
        android:angle="225" />
    </shape>
   </item>    
 </layer-list> 

Could someone help me and tell me what is wrong in there? Thanks to all of you guys


Thanks to Ameer, after i changed my Activity reference, i tried to setText with integer, basic error. Works perfectly thanks

4

2 回答 2

3

I think you should call it with the reference of your Activity Context, not with the reference of view.

于 2013-05-31T09:59:31.617 回答
0

Check your import and be sure you have not imported "android.R" but "your.package.R" instead. It is a common mistake when using the automatic import with Eclipse.

于 2013-05-31T10:04:13.000 回答