java - pass integer array from one class to another -
i having 2 classes. trying plot graph database values not able send value 1 class another, array being used. please go through code , me out.
following class values of array present(right using static values)
import java.util.arraylist; import java.util.hashmap; import java.util.list; import java.util.map; import org.achartengine.chartdemo.demo.chart.idemochart; import org.achartengine.chartdemo.demo.chart.temperaturechart; import android.app.listactivity; import android.content.intent; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.listview; import android.widget.simpleadapter; public class chartdemo extends listactivity { double = 10; double pass[] = { 7, 0, 4, 8, 3, 5, 7, 6, 8, 19, 11, 4 }; intent intent; private idemochart[] mcharts = new idemochart[] { new temperaturechart() }; private string[] mmenutext; private string[] mmenusummary; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); int length = mcharts.length; mmenutext = new string[length]; mmenusummary = new string[length]; temperaturechart obj=new temperaturechart(); obj.getarray(pass); for(int i=0;i<pass.length;i++) { log.i("sanket",pass[i]+""); } (int = 0; < length; i++) { mmenutext[i] = mcharts[i].getname(); mmenusummary[i] = mcharts[i].getdesc(); } setlistadapter(new simpleadapter(this, getlistvalues(), android.r.layout.simple_list_item_2, new string[] { idemochart.name, idemochart.desc }, new int[] { android.r.id.text1, android.r.id.text2 })); } private list<map<string, string>> getlistvalues() { list<map<string, string>> values = new arraylist<map<string, string>>(); int length = mmenutext.length; (int = 0; < length; i++) { map<string, string> v = new hashmap<string, string>(); v.put(idemochart.name, mmenutext[i]); v.put(idemochart.desc, mmenusummary[i]); values.add(v); } return values; } @override protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); // intent = new intent(this, temperaturechart.class); // if (position <= mcharts.length + 1) { intent = mcharts[position].execute(this); // intent.putextra("sam", a); // log.i("sanket",a+""); // } startactivity(intent); } }
now second class want array values problem class being initialized before filling items in array array in class empty
package org.achartengine.chartdemo.demo.chart; import org.achartengine.chartfactory; import org.achartengine.chart.barchart.type; import org.achartengine.model.rangecategoryseries; import org.achartengine.model.xymultipleseriesdataset; import org.achartengine.renderer.simpleseriesrenderer; import org.achartengine.renderer.xymultipleseriesrenderer; import android.content.context; import android.content.intent; import android.graphics.color; import android.graphics.paint.align; import android.util.log; /** * temperature demo range chart. */ public class temperaturechart implements idemochart { // static double b; double[] maxvalues; public void getarray(double array1[]) { array1 = new double[12]; this.maxvalues = array1; for(int i=0;i<array1.length;i++) { log.i("sanket",maxvalues[i]+""); } } /** * returns chart name. * * @return chart name */ public string getname() { return "marks range chart"; } /** * returns chart description. * * @return chart description */ public string getdesc() { return "the monthly marks (vertical range chart)"; } /** * executes chart demo. * * @param context * context * @return built intent */ public intent execute(context context) { // b = getintent().getintextra("sam", 0); // log.i("sanket",b+""); double[] minvalues = new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // double[] maxvalues = new double[] { 7, 0, 4, 8, 3, 5, 7, 6, 8, 19, // 11, // 4 }; xymultipleseriesdataset dataset = new xymultipleseriesdataset(); rangecategoryseries series = new rangecategoryseries("marks"); int length = minvalues.length; (int k = 0; k < length; k++) { series.add(minvalues[k], maxvalues[k]); } dataset.addseries(series.toxyseries()); int[] colors = new int[] { color.cyan }; xymultipleseriesrenderer renderer = buildbarrenderer(colors); setchartsettings(renderer, "monthly marks range", "month", "marks obtained", 0.5, 12.5, 0, 20, color.gray, color.ltgray); renderer.setbarspacing(0.5); renderer.setxlabels(0); renderer.setylabels(10); renderer.addxtextlabel(1, "jan"); renderer.addxtextlabel(3, "mar"); renderer.addxtextlabel(5, "may"); renderer.addxtextlabel(7, "jul"); renderer.addxtextlabel(10, "oct"); renderer.addxtextlabel(12, "dec"); renderer.addytextlabel(5, "ok"); renderer.addytextlabel(10, "good"); renderer.addytextlabel(20, "nice"); renderer.setmargins(new int[] { 30, 70, 10, 0 }); renderer.setylabelsalign(align.right); simpleseriesrenderer r = renderer.getseriesrendererat(0); r.setdisplaychartvalues(true); r.setchartvaluestextsize(12); r.setchartvaluesspacing(3); r.setgradientenabled(true); r.setgradientstart(-20, color.blue); r.setgradientstop(20, color.green); return chartfactory.getrangebarchartintent(context, dataset, renderer, type.default, "marks range"); } protected void setchartsettings(xymultipleseriesrenderer renderer, string title, string xtitle, string ytitle, double xmin, double xmax, double ymin, double ymax, int axescolor, int labelscolor) { renderer.setcharttitle(title); renderer.setxtitle(xtitle); renderer.setytitle(ytitle); renderer.setxaxismin(xmin); renderer.setxaxismax(xmax); renderer.setyaxismin(ymin); renderer.setyaxismax(ymax); renderer.setaxescolor(axescolor); renderer.setlabelscolor(labelscolor); } protected xymultipleseriesrenderer buildbarrenderer(int[] colors) { xymultipleseriesrenderer renderer = new xymultipleseriesrenderer(); renderer.setaxistitletextsize(16); renderer.setcharttitletextsize(20); renderer.setlabelstextsize(15); renderer.setlegendtextsize(15); int length = colors.length; (int = 0; < length; i++) { simpleseriesrenderer r = new simpleseriesrenderer(); r.setcolor(colors[i]); renderer.addseriesrenderer(r); } return renderer; } }
don't know doing here:
public void getarray(double array1[]) { array1 = new double[12]; this.maxvalues = array1; for(int i=0;i<array1.length;i++) { log.i("sanket",maxvalues[i]+""); } }
you overwriting input param array1 new double[12] , therefore this.maxvalues.
Comments
Post a Comment