Capturing ACTION_MOVE events over multiple OnTouchListener

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Capturing ACTION_MOVE events over multiple OnTouchListener

Postby RF » Mon Apr 27, 2009 7:54 pm

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’t “transfer” the 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!

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.blah.myRun
  3.  
  4.  
  5.  
  6. import android.app.Activity;
  7.  
  8. import android.os.Bundle;
  9.  
  10. import android.view.MotionEvent;
  11.  
  12. import android.view.View;
  13.  
  14. import android.widget.ImageView;
  15.  
  16. import android.widget.TextView;
  17.  
  18. import android.widget.Toast;
  19.  
  20.  
  21.  
  22. public class sticks extends Activity implements View.OnTouchListener {
  23.  
  24.       /** Called when the activity is first created. */
  25.  
  26.       ImageView img1, img2, img3, img4, img5, img6
  27.  
  28.       TextView myText;
  29.  
  30.  
  31.  
  32.       @Override
  33.  
  34.       public void onCreate(Bundle savedInstanceState) {
  35.  
  36.               super.onCreate(savedInstanceState);
  37.  
  38.               setContentView(R.layout.main);
  39.  
  40.  
  41.  
  42.               /** Create instances to the individual images */
  43.  
  44.               img1 = (ImageView) findViewById(R.id.button1);
  45.  
  46.               img2 = (ImageView) findViewById(R.id.button2);
  47.  
  48.               img3 = (ImageView) findViewById(R.id.button3);
  49.  
  50.               img4 = (ImageView) findViewById(R.id.button4);
  51.  
  52.               img5 = (ImageView) findViewById(R.id.button5);
  53.  
  54.               img6 = (ImageView) findViewById(R.id.button6);
  55.  
  56.               myText = (TextView)findViewById(R.id.myText);
  57.  
  58.  
  59.  
  60.               /** Bind instances to listeners */
  61.  
  62.               img1.setOnTouchListener(this);
  63.  
  64.               img2.setOnTouchListener(this);
  65.  
  66.               img3.setOnTouchListener(this);
  67.  
  68.               img4.setOnTouchListener(this);
  69.  
  70.               img5.setOnTouchListener(this);
  71.  
  72.               img6.setOnTouchListener(this);
  73.  
  74.  
  75.  
  76.  
  77.  
  78.       }
  79.  
  80.  
  81.  
  82.  
  83.  
  84.       @Override
  85.  
  86.       public boolean onTouch(View v, MotionEvent event) {
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.               /** On move, figure out which button the movement is on*/
  95.  
  96.  
  97.  
  98.  
  99.  
  100.               switch (event.getAction()) {
  101.  
  102.               case MotionEvent.ACTION_MOVE: {
  103.  
  104.                       myText.setText(v.toString());
  105.  
  106.  
  107.  
  108.               break;
  109.  
  110.               }
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.               return true;
  121.  
  122.  
  123.  
  124.  
  125.  
  126.       }
  127.  
  128.  
  129.  
  130.  
  131.  
  132. }
  133.  
  134.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4
RF
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Apr 27, 2009 7:49 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 4 guests