1
votes

I am not expert in programming. I have implemented acceleration sensor in Android program. I have used textview to display acceleration data for x, y & z axis.

Now using this sensor data I want to plot a real time graph. So is it good idea to put the textview in an array list & than plot graph?? Or some one has a better solution.

How to add textview's data into arraylist? How to plot graph of this real time sensor data??

This is my program.

public class HelloAndroid extends Activity implements SensorEventListener { private SensorManager sensorManager;

TextView xCoor; // declare X axis object
TextView yCoor; // declare Y axis object
TextView zCoor; // declare Z axis object

@Override
public void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    xCoor=(TextView)findViewById(R.id.xcoor); // create X axis object
    yCoor=(TextView)findViewById(R.id.ycoor); // create Y axis object
    zCoor=(TextView)findViewById(R.id.zcoor); // create Z axis object

    sensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
    // add listener. The listener will be HelloAndroid (this) class
    sensorManager.registerListener(this,
            sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
            SensorManager.SENSOR_DELAY_NORMAL);


    }

public void onAccuracyChanged(Sensor sensor,int accuracy){

}

public void onSensorChanged(SensorEvent event){


    if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){

        // assign directions
        float x=event.values[0];
        float y=event.values[1];
        float z=event.values[2];

        xCoor.setText("X: "+x);
        yCoor.setText("Y: "+y);
        zCoor.setText("Z: "+z);
    }
}

}

2

2 Answers

0
votes

You can watch for Changes in your TextView and run your code eg. :

    editText.addTextChangedListener(new TextWatcher() {
                    public void afterTextChanged(Editable s) {

                    }
                    public void beforeTextChanged(CharSequence s, int start, int count,
int after) {

                    }
                    public void onTextChanged(CharSequence s, int start, int before,     int count) {
                            String[] array = new String[] {TextView.getText().toString() , TextView1.getText().toString()
//Correct me if iam Wrong ...  } 
                    }
    });
0
votes

If you just want to put TextView into arrayList

List<TextView> textViews= new ArrayList<TextView>();
textViews.add(TextView1);
textViews.add(TextView2);
textViews.add(TextView3);