Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable multiple clicks on menu option in android

How do you disable multiple clicks on a menu option, before the first click is processed?

like image 693
aj10 Avatar asked Oct 17 '25 19:10

aj10


2 Answers

You can set the visibility or enable/disable the item by code.

MenuItem item = menu.findItem(R.id.your_item);
item.setVisible(true);
item.setEnabled(false);

Of course you have to check somewhere whether to enable oder disable the icon.

like image 68
Flo Avatar answered Oct 20 '25 11:10

Flo


Psuedo/Android answer:

 private boolean clicked = false;

 @Override
 public onClick(View v){
   if(!clicked){
       clicked = true;


       // do your processing - one click only


       super.onClick();
   }
 }

EDIT

or even better after the first click you can call yourView.setOnClickListener(null); to remove the onClick

like image 29
Blundell Avatar answered Oct 20 '25 11:10

Blundell