In the previous post (How to Build an Android App That Displays Live Accelerometer Data Using a Line Chart Control) I showed you how to instantiate the accelerometer and display live streaming data in a line chart. In this post we will add a “needle” which is a frequently used element of the seismograph experience. Тhe needle will be a view that will synchronize its vertical position with any new point we add to the chart. This is how the final result will look like:
NB: The needle is the red triangle on the right :)
Taking into consideration the workflow diagram from the previous post you can safely assume that the position of the needle will be updated in the onSensorChanged method.
The only thing left is to show you how the needle updates its position. Updating the position of a view in Android can be done in several ways. In this case I've chosen to update the position of the needle by overriding its onDraw method. The code snippet bellow shows that as soon as the updatePosition method is called it invalidates the layout of the needle which subsequently triggers onDraw.
And this is how you can synchronize the position of a visual element with the position of a new data point.
The full code can be found here: https://github.com/telerik/Android-samples/tree/master/Blogs/Seismograph/V2
Download Telerik Chart for Android from here
Read more about UI for Android here
Hi, I'm Kiril and I'm the Product Manager of Telerik UI for Android, Windows Universal and Windows Phone. Feel free to ping me on +KirilStanoev or @KirilStanoev