Capturing ACTION_MOVE events over multiple OnTouchListener

by RF » Mon, 27 Apr 2009 16:26:04 GMT


Sponsored Links
 Hello Folks!

I am developing an application where at one point the user is
presented with six identical images each placed side by side.  The
user can then select any of the six images, one after another, by
swiping his finger over the desired images he wishes to select.

I have used a table layout to place the images side by side within
image views for each of the images. Then I set OnTouchListener for
each ImageView.  The OnTouchListener listens for an ACTION_MOVE
MotionEvent whereby a textbox is set to display the view on which the
motion event was captured on.

My problem lies in coding the part where the user makes the selection
by swiping his finger over the images. The OnTouchListener captures
the motion event on the first image the user swipes his finger on but
it doesn ransferthe listener to the other images while the user
keeps swiping his finger over the other images. This results in the
motion being captured on just one image all the time even while the
user continues swiping his finger over other images.

How should I code this so that the program detects the user swiping
his finger over multiple images one by one?

This has been bugging me for two days now. Any help will be
appreciated!

Here's my code:

package com.blah.myRun

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class sticks extends Activity implements View.OnTouchListener {
       /** Called when the activity is first created. */
       ImageView img1, img2, img3, img4, img5, img6
       TextView myText;

       @Override
       public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
               setContentView(R.layout.main);

               /** Create instances to the individual images */
               img1 = (ImageView) findViewById(R.id.button1);
               img2 = (ImageView) findViewById(R.id.button2);
               img3 = (ImageView) findViewById(R.id.button3);
               img4 = (ImageView) findViewById(R.id.button4);
               img5 = (ImageView) findViewById(R.id.button5);
               img6 = (ImageView) findViewById(R.id.button6);
               myText = (TextView)findViewById(R.id.myText);

               /** Bind instances to listeners */
               img1.setOnTouchListener(this);
               img2.setOnTouchListener(this);
               img3.setOnTouchListener(this);
               img4.setOnTouchListener(this);
               img5.setOnTouchListener(this);
               img6.setOnTouchListener(this);


       }


       @Override
       public boolean onTouch(View v, MotionEvent event) {



               /** On move, figure out which button the movement is
on*/


               switch (event.getAction()) {
               case MotionEvent.ACTION_MOVE: {
                       myText.setText(v.toString());

               break;
               }




               return true;


       }


}

--~--~---------~--~----~------------~-------~--~----~



Capturing ACTION_MOVE events over multiple OnTouchListener

by RF » Mon, 27 Apr 2009 16:28:31 GMT


 Hello Folks!

I am developing an application where at one point the user is
presented with six identical images each placed side by side.  The
user can then select any of the six images, one after another, by
swiping his finger over the desired images he wishes to select.

I have used a table layout to place the images side by side within
image views for each of the images. Then I set OnTouchListener for
each ImageView.  The OnTouchListener listens for an ACTION_MOVE
MotionEvent whereby a textbox is set to display the view on which the
motion event was captured on.

My problem lies in coding the part where the user makes the selection
by swiping his finger over the images. The OnTouchListener captures
the motion event on the first image the user swipes his finger on but
it doesn ransferthe listener to the other images while the user
keeps swiping his finger over the other images. This results in the
motion being captured on just one image all the time even while the
user continues swiping his finger over other images.

How should I code this so that the program detects the user swiping
his finger over multiple images one by one?

This has been bugging me for two days now. Any help will be
appreciated!

Here's my code:

package com.blah.myRun

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class sticks extends Activity implements View.OnTouchListener {
       /** Called when the activity is first created. */
       ImageView img1, img2, img3, img4, img5, img6
       TextView myText;

       @Override
       public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
               setContentView(R.layout.main);

               /** Create instances to the individual images */
               img1 = (ImageView) findViewById(R.id.button1);
               img2 = (ImageView) findViewById(R.id.button2);
               img3 = (ImageView) findViewById(R.id.button3);
               img4 = (ImageView) findViewById(R.id.button4);
               img5 = (ImageView) findViewById(R.id.button5);
               img6 = (ImageView) findViewById(R.id.button6);
               myText = (TextView)findViewById(R.id.myText);

               /** Bind instances to listeners */
               img1.setOnTouchListener(this);
               img2.setOnTouchListener(this);
               img3.setOnTouchListener(this);
               img4.setOnTouchListener(this);
               img5.setOnTouchListener(this);
               img6.setOnTouchListener(this);


       }


       @Override
       public boolean onTouch(View v, MotionEvent event) {



               /** On move, figure out which button the movement is
on*/


               switch (event.getAction()) {
               case MotionEvent.ACTION_MOVE: {
                       myText.setText(v.toString());

               break;
               }




               return true;


       }


}

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Capturing ACTION_MOVE events over multiple OnTouchListener

by RF » Mon, 27 Apr 2009 16:33:44 GMT


 Hello Folks!

I am developing an application where at one point the user is
presented with six identical images each placed side by side.  The
user can then select any of the six images, one after another, by
swiping his finger over the desired images he wishes to select.

I have used a table layout to place the images side by side within
image views for each of the images. Then I set OnTouchListener for
each ImageView.  The OnTouchListener listens for an ACTION_MOVE
MotionEvent whereby a textbox is set to display the view on which the
motion event was captured on.

My problem lies in coding the part where the user makes the selection
by swiping his finger over the images. The OnTouchListener captures
the motion event on the first image the user swipes his finger on but
it doesn ransferthe listener to the other images while the user
keeps swiping his finger over the other images. This results in the
motion being captured on just one image all the time even while the
user continues swiping his finger over other images.

How should I code this so that the program detects the user swiping
his finger over multiple images one by one?

This has been bugging me for two days now. Any help will be
appreciated!

Here's my code:

package com.blah.myRun

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class sticks extends Activity implements View.OnTouchListener {
        /** Called when the activity is first created. */
        ImageView img1, img2, img3, img4, img5, img6
        TextView myText;

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                /** Create instances to the individual images */
                img1 = (ImageView) findViewById(R.id.button1);
                img2 = (ImageView) findViewById(R.id.button2);
                img3 = (ImageView) findViewById(R.id.button3);
                img4 = (ImageView) findViewById(R.id.button4);
                img5 = (ImageView) findViewById(R.id.button5);
                img6 = (ImageView) findViewById(R.id.button6);
                myText = (TextView)findViewById(R.id.myText);

                /** Bind instances to listeners */
                img1.setOnTouchListener(this);
                img2.setOnTouchListener(this);
                img3.setOnTouchListener(this);
                img4.setOnTouchListener(this);
                img5.setOnTouchListener(this);
                img6.setOnTouchListener(this);


        }


        @Override
        public boolean onTouch(View v, MotionEvent event) {



                /** On move, figure out which button the movement is on*/


                switch (event.getAction()) {
                case MotionEvent.ACTION_MOVE: {
                        myText.setText(v.toString());

                break;
                }




                return true;


        }


}

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Which one scales with the screen... Dip, sp, px.....?

Given the recent discovery with the cupcake emulator I'm trying to re-work
the layout file so it's cupcake friendly and future proofed, but have hit a
problem.

What I want is for 6 buttons to take up a total of three quarters of the
screen width, but I can't seem to find the measurement unit which correlates
to this. All I've found is;

px  : Not screen resolution independent, so something that works on a
320x480 screen won't take 3/4s of the screen on different resolution
display.

dip : Scales with pixel density and not screen resolution, so the object
won't scale up as the physical screen size gets bigger.
Pt, in & mm : Don't scale with screen size so a 1 unit button is the same
size on a 3 or 30 inch screen.

sp : Based on font size and there's no guaranteed correlation between font
width and screen width. 


The closest I've got is the following;

<TableLayout    android:layout_gravity="center_horizontal"
                        android:layout_height="wrap_content"
                        android:layout_width="fill_parent">
<TableRow>
        <Button android:id="@+id/button1"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"/>
        <Button android:id="@+id/button2"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"/>
        <Button android:id="@+id/button3"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"/>
        <Button android:id="@+id/button4"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"/>
        <Button android:id="@+id/button5"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"/>
        <Button android:id="@+id/button6"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"/>                      
</TableRow>
</TableLayout>

But this results in buttons with uneven widths which is not what I'm after.


Does anyone have a solution?

Al.


---

* Written an Android App? - List it at http://andappstore.com/ *

======
Funky Android Limited is registered in England & Wales with the 
company number  6741909. The registered head office is Kemp House, 
152-160 City Road, London,  EC1V 2NX, UK. 

The views expressed in this email are those of the author and not 
necessarily those of Funky Android Limited, it's associates, or it's 
subsidiaries. 



--~--~---------~--~----~------------~-------~--~----~

2. Android Touch Inputs via adb

Hello,

Is there any way to issue touch events via adb.  For example issue a
touch event at coordinate (0,0).  I know you can issues keyevents and
string inputs via adb shell input.

Please let me know.

Thanks,
Frank
--~--~---------~--~----~------------~-------~--~----~

3. Audio SetParameter() use

4. Static librari is not linking with functions like abs, sincos etc.

5. Static librari is not linking with functions like abs, sincos etc.

6. Definite need for a Cupcake SDK & release details.

7. I want run my application in background, with "Service component"