Nishant
Nishant

Reputation: 32233

Handling quick succession taps on overlay items

I have created a map application to show near by places on the map.When the user clicks on the pin on the map a Alert dialog box pops up asking user to show the route.My problem is that when the pin is clicked many times at quick succession the message box is appearing more than once.I don't want that message to appear more than once.Can anyone help me in this? My code is:

    protected boolean onTap(int pos) {

    final ProgressDialog myDialog = ProgressDialog.show(LocationBasedServicesV1.this, "", "Please Wait...");
         OverlayItem item = items.get(pos);
          Thread backgroundThread = new Thread(new Runnable(){
        @Override
        public void run() {
             runOnUiThread(new Runnable() {                    
             @Override
              public void run() {
                 AlertDialog.Builder dialog = new AlertDialog.Builder(  LocationBasedServicesV1.this);
                dialog.setTitle(listDetailsVO.getName());
                dialog.setMessage("Address: "+destination+"\nPhone: "+finalPhone+"\nEmail Id: "+finalEmail+"\nDistance: "+finalDistance+unit);
                dialog.setPositiveButton("Show Route", new DialogInterface.OnClickListener(){
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                    try {
                        Intent i = new Intent(LocationBasedServicesV1.this, ShowRouteActivity.class);
                        i.putExtra("destination", destination);
                        i.putExtra("source", currentAddress);
                        startActivity(i);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
            });
            dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
           });
         dialog.show();
         }
        }); 
        myDialog.dismiss();
        }
        });
        backgroundThread.start();
    }

Upvotes: 0

Views: 128

Answers (1)

Pratik
Pratik

Reputation: 30855

check the position for pin suppose you have 5 pin then user click on 3 position pin again user click on same pin then you got the same position into the onTap() method then just do nothing otherwise just dismiss the last open (if you required) and create new dialog/ use existing dialog and show on that position

Upvotes: 1

Related Questions