Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i place double click event on ImageView in Android

I have to place an double click event on Image view..Whenever I double click on Image ,It sshould be Zoom.But I found that there is no such event like double click in Image Veiw. Can Anyone Tell me How To DO it?? Thanks in Advance..

like image 323
Nirav Bhandari Avatar asked Mar 04 '11 08:03

Nirav Bhandari


2 Answers

Try this approach:

  • add boolean doubleClick = false;
  • and Handler doubleHandler
  • in onClick check if doubleClick is true
  • if true, it is a double click
  • if not, set doubleClick to true and use the handlers postDelayed to set it back to false after i.e. 500ms
like image 106
Maaalte Avatar answered Sep 30 '22 14:09

Maaalte


whenever the onClick() is called the new instance of Handler is created, if the Handler object is instantiated inside onClick(). So, instantiate handler outside onClick().

boolean isDoubleClicked=false;

Handler handler=new Handler();
Runnable r=new Runnable(){
  @Override
  public void run(){
    //Actions when Single Clicked
    isDoubleClicked=false;
  }
}

tv.setOnClickListener(new onClickListener){
  @Override
  public void onClick(View view){
    if(isDoubleClicked){
      //Actions when double Clicked
      isDoubleClicked=false;
      //remove callbacks for Handlers
      handler.removeCallbacks(r);
    }else{
      isDoubleClicked=true;
      handler.postDelayed(r,500);
    }
  }
}
like image 42
Shamivul ruvaid Avatar answered Sep 30 '22 16:09

Shamivul ruvaid