java - AndroidPlot: LineAndPointFormatter causing crash when passing in Context and colors.xml resource ID -
i'm trying avoid using rgb values, method:
public lineandpointformatter(integer linecolor, integer vertexcolor, integer fillcolor) { this(linecolor, vertexcolor, fillcolor, filldirection.bottom); }
where i'm supposed pass in:
lineandpointformatter lpf = new lineandpointformatter(color.rgb(0, 0, 200), null, color.rgb(0, 0, 80));
is working fine, want use method:
public lineandpointformatter(context ctx, int xmlcfgid) { // prevent configuration of classes derived one: if (getclass().equals(lineandpointformatter.class)) { configurator.configure(ctx, this, xmlcfgid); } }
so can use colors.xml resource id , manage graph colors setting "colorid" passing in later (colorid showing -65536 in log or variation of depending on ). code inside class that's extending fragment, i'm wondering if i'm getting context correct..
here of things i've tried:
lineandpointformatter seriesformat = new lineandpointformatter(getactivity().getapplicationcontext(), getresources().getcolor(r.color.blue)); lineandpointformatter seriesformat = new lineandpointformatter(getactivity().getapplicationcontext(), colorid); lineandpointformatter seriesformat = new lineandpointformatter(getactivity().getapplicationcontext(), getresources().getcolor(colorid));
and on..
i'll keep pluggin away, if using context version of lineandpointformatter, maybe you've run similar problem?
the exception looks this:
05-14 12:47:25.917: e/androidruntime(14023): android.content.res.resources$notfoundexception: resource id #0xff0000ff
do have rewrite colors #ff0000ff format??
edit: added colors.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="white">#ffffff</color> <color name="transparent_white">#66ffffff</color> <color name="yellow">#ffff00</color> <color name="fuchsia">#ff00ff</color> <color name="red">#ff0000</color> <color name="silver">#c0c0c0</color> <color name="gray">#808080</color> <color name="olive">#808000</color> <color name="purple">#800080</color> <color name="maroon">#800000</color> <color name="aqua">#00ffff</color> <color name="lime">#00ff00</color> <color name="teal">#008080</color> <color name="green">#008000</color> <color name="blue">#0000ff</color> <color name="navy">#000080</color> <color name="black">#000000</color> </resources>
i think problem using xml resource contains elements not related object being configured "configurator". configurator uses reflection figure out how map xml values members of associated object. end, important xml file only contain elements actual members of object being configured , elements share same name of members.
in example above trying configure lineandpointformatter using xml file containing elements names silver, gray etc. not exist. instead should store config in separate xml file looking this:
<?xml version="1.0" encoding="utf-8"?> <config vertexpaint.color="#00ff00" linepaint.color="#00ff00" linepaint.strokewidth="2dp"/>
once you've defined file can try (i've not tried assume should work) reference values in colors.xml when adjust definition of color gray example, adjusted globally.
Comments
Post a Comment