在achartengine实施触摸

时间:2013-07-30 11:44:07

标签: android achartengine

我想在LineGraph上触摸点上的值。为此,我尝试使用OnTouch()内部方法,但它不适合我。我不知道如何开始,因为我是achartengine的新手。 我试过了..

public class DynamicGraphActivity extends Activity {

private static GraphicalView view;
private LineGraph line = new LineGraph();
private static Thread thread;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    thread = new Thread() {
        public void run()
        {
            for (int i = 1; i < 31; i++) 
            {

                Point p = MockData.getDataFromReceiver(i); // We got new data!
                line.addNewPoints(p); // Add it to our graph
                view.repaint();
            }
        }
    };
    thread.start();



}
public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub

    switch (event.getAction()) {
    case MotionEvent.ACTION_MOVE:
        displaycoordinates(event);
        break;

    case MotionEvent.ACTION_DOWN:
        displaycoordinates(event); 
        break;                  
    default:
        break;
    }
    return true;
}           

public void displaycoordinates(MotionEvent event) {
    // TODO Auto-generated method stub

    float x = event.getX();
    float y = event.getY();

    PointF point = new PointF(x,y);

    NumberFormat nf = new DecimalFormat("#0.00");

    //Double j = getXval(x);
    String xval = nf.format(x);

    //  Double k = point.getYvalue(y);
    String yval = nf.format(y);


    Toast toast = Toast.makeText(getApplicationContext(), xval+"xval"+yval+" yval", 0);
    toast.show();


}
@Override
protected void onStart() {
    super.onStart();
    view = line.getView(this);
    setContentView(view);
}

}

1 个答案:

答案 0 :(得分:0)

我认为你是从错误的方向开始的。我建议您查看this示例,以了解如何处理图表上的点击事件并检索有关最近点的一些信息。