I am creating sound meter app in android I want to show values in line graph on real time anyone please tell me how I can do it?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
For time operations please see android.text.format.Time http://developer.android.com/reference/android/text/format/Time.html
This is official sample code from there:
Time time = new Time();
time.set(4, 10, 2007); // set the date to Nov 4, 2007, 12am
time.normalize(false); // this sets isDst = 1
time.monthDay += 1; // changes the date to Nov 5, 2007, 12am
millis = time.toMillis(false); // millis is Nov 4, 2007, 11pm
millis = time.toMillis(true); // millis is Nov 5, 2007, 12am
Now for showing the graph there is no ready class, so you will have to draw it yourself by overriding the Draw()
function of View
class, or to search a library to do this, for example: http://android-graphview.org/
回答2:
When using AChartEngine, you just need to add the new values to the series and call mChartView.repaint()
in order to have the chart refresh with the new updates.
回答3:
in onCreate(...):
GraphView graphView = new LineGraphView(this, "Amplitude");
graphView.setScrollable(true);
graphView.setViewPort(0, 30); // the x range you want to show without scrolling
GraphViewSeries graphSeries = new GraphViewSeries(new GraphViewDataInterface[0]);
graphView.addSeries(graphSeries);
setContentView(graphView);
//or add your graphView to the Activity's view as appropriate
then, as you get new values:
graphSeries.appendData(new GraphView.GraphViewData(xValue, yValue), true, 300);
//where 300 is the maximum number of values to keep
New values will come in on the right, and the GraphView will automatically scroll to show the most recent data on the chart.