2011-01-04 10 views
6

Có bất kỳ loại onPress và onRelease cho các nút android như trong flash không?onPress/onRelease trong Android

+0

Nếu bạn thực hiện 'KeyboardView.OnKeyboardActionListener', sau đó bạn sẽ có quyền truy cập cho 'onPress()' và 'onRelease()' –

+0

@IgorGanapolsky là sai và đây là câu hỏi 5 năm cũ ... – nebkat

+0

Tùy thuộc vào cách bạn nhìn vào nó: http://developer.android.com/reference/android/inputmethodservice/KeyboardView.OnKeyboardActionListener .html # onRelease (int). Nhưng không thực sự cho các nút. –

Trả lời

1

Hãy xem Handling UI Events trên tài liệu android, bạn đặc biệt muốn onTouch nếu bạn muốn nghe xuống và phát hành. Nếu bạn đang làm điều này chỉ để thay đổi giao diện của một nút thì có nhiều cách khác để xử lý nút này bằng cách sử dụng state lists.

13

Đó là quá muộn, nhưng có lẽ ai đó sẽ tìm thấy nó hữu ích:

mButton.setOnTouchListener(new OnTouchListener() 
     { 

      @Override 
      public boolean onTouch(View v, MotionEvent event) 
      { 
       if (event.getAction() == MotionEvent.ACTION_DOWN) 
        Log.d("Pressed", "Button pressed"); 
       else if (event.getAction() == MotionEvent.ACTION_UP) 

       Log.d("Released", "Button released"); 
       // TODO Auto-generated method stub 
       return false; 
      } 
     }); 
+0

cảm ơn :) nó đã giúp tôi ~ – Sunny

1

Bạn có thể thay đổi mButton, thay vào đó là của bạn là gì. Và bạn có thể thêm ngoặc sau ifelse if

mButton.setOnTouchListener(new OnTouchListener() 
    { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) 
     { 
      if (event.getAction() == MotionEvent.ACTION_DOWN) 
       Log.d("Pressed", "Button pressed"); 
      else if (event.getAction() == MotionEvent.ACTION_UP) 

      Log.d("Released", "Button released"); 
      // TODO Auto-generated method stub 
      return false; 
     } 
    }); 

và mã này là từ bên cạnh tôi:

// butona basınca bir ses çekince bir ses geliyor. 
    sescal.setOnTouchListener(new OnTouchListener() 
    { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) 
     { 
      if (event.getAction() == MotionEvent.ACTION_DOWN) 
      { 

       Log.d("Pressed", "Button pressed"); 
       mp.start(); 
      } 
      else if (event.getAction() == MotionEvent.ACTION_UP) 
      { 

       Log.d("Released", "Button released"); 
       mp2.start(); 
      } 
      // TODO Auto-generated method stub 
      return false; 
     } 
    });