memory - How to have a Moving graph or chart in android? -
i new android , need know how make graph or chart (eg. line chart) move i.e, right left.
basically going draw graph in accordance ram memory usage of phone. need draw graph present in task manager of windows.
please on this.
it's sample code.
i did not test yet.
but think code works fine.
public class drawgraph extends activity{ /** * variable array graphview * verlabel : background height values * horlabel : background width values * values : max values of foreground active graph */ private float[] values = new float[60]; private string[] verlabels = new string[] { "600","500","400","300","200","100","80","60","40","20","0", }; private string[] horlabels = new string[] { "0","10", "20", "30", "40", "50", "60"}; private graphview graphview; private linearlayout graph; private boolean runnable = false; @override public void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); setcontentview(r.layout.main); graph = (linearlayout)findviewbyid(r.id.graph); graphview = new graphview(drawgraph.this, values, "test graph", horlabels, verlabels, graphview.line); graph.addview(graphview); runnable = true; startdraw.start(); } @override public void ondestroy(){ super.ondestroy(); runnable = false; } public void setgraph(int data){ for(int i=0; i<values.length-1; i++){ values[i] = values[i+1]; } values[values.length-1] = (float)data; graph.removeview(graphview); graph.addview(graphview); } public handler handler = new handler(){ @override public void handlemessage(android.os.message msg){ switch(msg.what){ case 0x01: int testvalue = (int)(math.random() * 600)+1; setgraph(testvalue); break; } } } public thread startdraw = new thread(){ @override public void run(){ while(runnable){ handler.sendemptymessage(0x01); try{ thread.sleep(1000); } catch (exception e){ e.printstacktrace(); } } } }
Comments
Post a Comment