khannasarthak
8/31/2017 - 1:53 AM

MC 18.53 run and stop working

MC 18.53 run and stop working

package com.healthmonitor.khann.healthmonitor;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
import android.widget.EditText;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.LineGraphSeries;
import com.jjoe64.graphview.series.Series;
import java.util.Random;
import static android.provider.AlarmClock.EXTRA_MESSAGE;
import android.widget.Button;
import android.view.View.OnClickListener;





public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button runButton = (Button) findViewById(R.id.run);
        runButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // ENTER REAL TIME CODE HERE

                GraphView graph = (GraphView) findViewById(R.id.graph);
                int size = 100;
                DataPoint[] dataPoints = new DataPoint[size];
                Random rand = new Random();
                int j = 0;
                for (int i = 0; i < size; i++) {
                    float x1 = j;
                    float y1 = rand.nextFloat() * (100 - 20) + 20;
                    dataPoints[i] = new DataPoint(x1, y1);
                    j++;

                }

                LineGraphSeries<DataPoint> series = new LineGraphSeries<>(dataPoints);
                graph.addSeries(series);

            }
        });


        Button stopButton = (Button) findViewById(R.id.stop);
        stopButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                GraphView graph = (GraphView) findViewById(R.id.graph);
                graph.removeAllSeries();


            }
        });


    }
}