2016-04-26 12 views
0

Ich habe den folgenden Code. Wenn ich es in die ACTION_DOWN stelle, funktioniert es, wenn ich es in die ACTION_UP stecke ist das nicht, was mache ich falsch?Android ProgressDialog.show nicht angezeigt

button1.setOnTouchListener(new View.OnTouchListener() { 
    public boolean onTouch(View view, MotionEvent event) { 
     if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) { 

      //it works here 
      // progress = ProgressDialog.show(ExampleAct.this,"Processing...","Preparing file", true); 

     } else if (event.getAction() == android.view.MotionEvent.ACTION_UP) { 
       //It doesn't work here 
       progress = ProgressDialog.show(ExampleAct.this,"Processing...","Preparing file", true); 
      //Other code here is working fine 
     } 
     return true; 
    } 

}); 

Antwort

0

Try ACTION_CANCEL im Fall von ACTION_UP hinzuzufügen.

Vielleicht die Eltern von button1 abfangen das TouchEvent. Und das Kind ACTION_CANCEL statt ACTION_UP

button1.setOnTouchListener(new View.OnTouchListener() { 
     public boolean onTouch(View view, MotionEvent event) { 
      if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) { 

       //it works here 
       // progress = ProgressDialog.show(ExampleAct.this,"Processing...","Preparing file", true); 

      } else if (event.getAction() == android.view.MotionEvent.ACTION_UP 
        ||event.getAction() == MotionEvent.ACTION_CANCEL 
        ) { 
       //It doesn't work here 
       progress = ProgressDialog.show(ExampleAct.this,"Processing...","Preparing file", true); 

      } 
      return true; 
     } 

    }); 
+0

zu bekommen habe ich vergessen, eine Sache hinzufügen, ich habe eigentlich einen anderen Code und es ist in Ordnung innerhalb des ACTION_UP Block –

+0

btw, der Code, den Sie einen Fehler zur Verfügung gestellt hat, wird ProgressDialog zweimal aufgerufen werden , eine für ACTION_UP und eine für CANCEL –