0

Hello i would like to ask, how can i Display Toast near the user click point Like on image below using GraphView library:

http://android-graphview.org/

enter image description here

Thanks for any advice

EDIT:

I tried it using

seriesSin = new GraphViewSeries("Sinus curve", new GraphViewSeries.GraphViewSeriesStyle(Color.rgb(200, 50, 00), 3), data);

   // SET ON TOUCH
        graphView.setOnTouchListener(new View.OnTouchListener(){
            public boolean onTouch(View v, MotionEvent event) {
                if(event.getAction() == MotionEvent.ACTION_DOWN) {
                    int size = seriesSin.size();
                    float screenX = event.getX();
                    float screenY = event.getY();
                    float width_x = v.getWidth();
                    float viewX = screenX - v.getLeft();
                    float viewY = screenY - v.getTop();
                    float percent_x = (viewX/width_x);
                    int pos = (int) (size*percent_x);

                    System.out.println("X: " + viewX + " Y: " + viewY +" Percent = " +percent_x);
                    System.out.println("YVal = " +seriesSin.getY(pos));
                    return true;
                }
                return false;
            }

        });

But I cannot to get seriesSin.size and seriesSin.getY(pos)

redrom
  • 11,502
  • 31
  • 157
  • 264

2 Answers2

0

You can't decide where to display the Toast. However, you could set up a custom view and show it using the coordinates (x and y) you get when detecting the touch. When you show the view, simply use those values to set up the layout params of the view, and voila.

Alessandro Roaro
  • 4,665
  • 6
  • 29
  • 48
0

Version 4.0.0 added an onTap() listener, that replicates your onTouch method above, it doesn't solve your Toast positioning issue, but could save you a few lines of code.

arober11
  • 1,969
  • 18
  • 31