How to set up a user dialog in a specific coordinate?

I am new to Android development and trying to figure out how to display the NewQuickAction3D popup dialog with a specific coordinate in the view. I integrate a popup with this tutorial . Essentially, I want to use a popup dialog box to display the data that users touch, instead of painting on canvas using "infoview". Currently, a popup is displayed at the top and center of the view to which I snap it. How can I get this to display a specific coordinate? Any help is greatly appreciated.

MY CODE

public void updateMsg(String t_info, float t_x, float t_y, int t_c){ infoView.updateInfo(t_info, t_x, t_y, t_c); //Infoview paints to on a specific coordinate quickAction.show(infoView); //How do I use the t_x & t_y coordinates here instead of just anchoring infoview 

EDIT

 public void updateMsg(String t_info, float t_x, float t_y, int t_c){ infoView.updateInfo(t_info, t_x, t_y, t_c); WindowManager.LayoutParams wmlp = quickAction.getWindow().getAttributes(); //Error here getting window attributes wmlp.gravity = Gravity.TOP | Gravity.LEFT; wmlp.x = 100; //x position wmlp.y = 100; //y position quickAction.show(infoView); } 
+5
source share
1 answer

Override onTouch () of your view

 AlertDialog dialog; @Override public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: showDialog(); // display dialog break; case MotionEvent.ACTION_MOVE: if(dialog!=null) dialog.dismiss(); // do something break; case MotionEvent.ACTION_UP: // do somethig break; } return true; } public void showDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(FingerPaintActivity.this); dialog = builder.create(); dialog.setTitle("my dialog"); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes(); wmlp.gravity = Gravity.TOP | Gravity.LEFT; wmlp.x = 100; //x position wmlp.y = 100; //y position dialog.show(); } 

Even for drawing, the user touches the screen, and then a dialog box is displayed. so close the dialog on the go.

+13
source

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


All Articles