0

I am just a couple of days in to programming with Android, and are facing problems with the touch events.

I am unable to detect the finger down and finger up events, the only event that seems to be triggered is a finger down, move followed by finger up, but all I am looking for is a click or finger down / finger up event.

  public boolean onTouchEvent(MotionEvent event) {
        int eva = event.getAction();

        switch (eva) {
            case MotionEvent.ACTION_DOWN: 
                break;

            case MotionEvent.ACTION_MOVE:
                break;

            case MotionEvent.ACTION_UP:   
                break;
        }

        Toast.makeText(getApplicationContext(),"Event", Toast.LENGTH_SHORT).show();
        return true; 
    }

in Javascript, this would simply be a click event, but it appears that it's not so easy with this ?

Edit

I should have mentioned that the view is a WebView and not a button, I am trying to capture a single tap anywhere on the screen:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <WebView 
        android:id="@+id/web_engine"  
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent"  
     /> 

</RelativeLayout>
Community
  • 1
  • 1
crankshaft
  • 2,607
  • 4
  • 45
  • 77

2 Answers2

0

You probably should be using the OnClick Listener Interface, as detailed here

A simple example would be like the one found here

   public class MyActivity extends Activity {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         setContentView(R.layout.content_layout_id);

         final Button button = (Button) findViewById(R.id.button_id);
         button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // Perform action on click
             }
         });
     }
 }
DigCamara
  • 5,540
  • 4
  • 36
  • 47
  • it's not about onClick i guess @Dig – Vamsi Pavan Mahesh Feb 05 '14 at 00:26
  • I hesitated a bit before I answered, @VamsiPavanMahesh , but (s)he says "but all I am looking for is a click or finger down / finger up event" and also "in Javascript, this would simply be a click event, but it appears that it's not so easy with this ?" – DigCamara Feb 05 '14 at 00:27
0

May be because of switch and break I think . What about using if instead of switch/break .

if(event.getAction() == MotionEvent.ACTION_DOWN){
}
if(event.getAction() == MotionEvent.ACTION_MOVE){
}

something like this .

Chann Lynn
  • 201
  • 1
  • 3
  • 14