Show a small popup at the point where the user clicks on the chart (achartengine)

I want to show a small popup at the point where the user clicks on the chart. I read the answer asked for the question

Displaying a pop-up window when you click a point in the AChartEngine chart

it offers a toast as an answer, but I want the user to choose between two parameters in popup. I tried using alertdialog and even created a user dialog, but they cover the entire area of ​​the screen, while I want only a small pop-up window in the place where user clicks on a graph.

Here is my onotuch listener where I get the x, y coordinate

     mChart.setOnTouchListener(new OnTouchListener() {
                if(event.getAction() == MotionEvent.ACTION_UP)
                              {                     
                    int xd= (int) event.getX();
                    int yd = (int) event.getY();
                                       }

Code for repositioning a dialog box

    AlertDialog alertDialog = builder.create();
    alertDialog.show();
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 
    lp.x= xd;
    lp.y= yd;
    alertDialog.getWindow().setAttributes(lp);                      
+4
1

ur

dialog.show();

Display display =((WindowManager)getSystemService(context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height=display.getHeight();

Log.v("width", width+"");
dialog.getWindow().setLayout((6*width)/7,(4*height)/5);

MotionEvent getX(), X, , getRawX(), X, .

, X, , :

 view.getLeft() + motionEvent.getX()

GetLeft()

+4

Source: https://habr.com/ru/post/1531734/


All Articles