how to use onclick and ontouch listener both for different functionality in android -


i developing android app, requirement. need different functionality on onclick , different functionality on stop , start method of ontouch. can 1 me? how can implement feature in android?

i understand problem , hope below code you.

public class myfragment extends basefragment implements view.ontouchlistener {      @override     public boolean ontouch(final view v, motionevent event) {         switch (event.getaction()) {             case motionevent.action_down:                 prev_timestamp = system.currenttimemillis();              case motionevent.action_up:                 current_timestamp = system.currenttimemillis();                 upcount++;                 if (current_timestamp - prev_timestamp < 250) {                      if (upcount == 2) {                         upcount = 0;                         log.d(tag, "click event");             //here code onclick event                     } else {                          new asynctask<void, void, void>() {                              @override                             protected void doinbackground(void... params) {                                 try {                                     thread.sleep(500);                                 } catch (interruptedexception e) {                                     e.printstacktrace();                                 }                                 return null;                             }                              @override                             protected void onpostexecute(void avoid) {                                 if (upcount != 0) {                                     touch_end=false;                                     log.d(tag, "touch start");                     //here code ontouchstart event                                 }                                 super.onpostexecute(avoid);                             }                         }.execute();                      }                 } else {                     upcount = 0;                     log.d(tag, "touch end");                     //here code ontouchend event                 }              case motionevent.action_cancel:                 //here code cancel eent if want          }         return true;     } } 

source :see example here


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -