Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6568937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:33:52+00:00 2026-05-25T14:33:52+00:00

I finally figured out how to enable multitouch, after about a week of trial

  • 0

I finally figured out how to enable multitouch, after about a week of trial and error. I’ve encountered another problem, however. First of all, let me give an explanation of my app.

This is a pretty basic app. When you touch AREA_A on the screen, it will play SOUND_A. When you touch AREA_B on the screen, it will play SOUND_B. Pretty simple. I wanted this to work with multitouch, so I used an OnTouch event. I am now able to touch AREA_A and AREA_B on the screen at the same time, and get a sound out of both areas (proof that multitouch is working), but here’s the problem. If I start touching AREA_A, and hold my finger there, then touch AREA_B (With my first finger still touching AREA_A), instead of hearing SOUND_B, I hear SOUND_A being played. I am baffled at why this is happening. I think things will be more clear if I paste the code, so here it is.
(I went ahead and added my entire class, just so you could examine it from start to finish).

package com.tst.tanner;

import android.app.Activity;
import android.graphics.Color;
import android.media.AudioManager; 
import android.media.SoundPool;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;


public class sp extends Activity implements OnTouchListener {
private SoundPool soundPool;
private int bdsound, sdsound;
float x, y;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // Set the hardware buttons to control the music
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    // Load the sound
    View v = (View) findViewById(R.id.view1);

    v.setOnTouchListener(this);

    soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
    bdsound = soundPool.load(this, R.raw.kickdrum1, 1);
    sdsound = soundPool.load(this, R.raw.sd, 1);

}

@Override
public boolean onTouch(View v, MotionEvent e) {
    // TODO Auto-generated method stub
    x = e.getX();
    y = e.getY();


    v.setBackgroundColor(Color.rgb(236,234,135));
    switch (e.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:

        if (x > 1 & x < 200 & y > 1 & y < 200) {
            soundPool.play(bdsound, 10, 10, 1, 0, 1);
        }
        if (x > 1 & x < 200 & y > 200 & y < 400) {
            soundPool.play(sdsound, 10, 10, 1, 0, 1);
        }

        break;

    case MotionEvent.ACTION_POINTER_1_DOWN:

        if
        (x > 1 & x < 200 & y > 1 & y < 200) {
            soundPool.play(bdsound, 10, 10, 1, 0, 1);
        }
        if (x > 1 & x < 200 & y > 200 & y < 400) {
            soundPool.play(sdsound, 10, 10, 1, 0, 1);
        }

        break;


    case MotionEvent.ACTION_UP:


        v.setBackgroundColor(Color.BLACK);

    }

    return true;
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    soundPool.release();
    finish();
}
}

Does anyone know what I am doing wrong? Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:33:52+00:00Added an answer on May 25, 2026 at 2:33 pm

    The getX() and getY() functions always return the position of the first pointer. I suspect that this is causing your problem.

    When you touch your second finger to the screen in Area B, the MotionEvent is of type ACTION_DOWN, so a sound will be played (just as you intended). However, since you touched Area A first, and are still touching it, that position is the one returned by getX() and getY().

    To get the positions of specific pointers try using the getX(int) and getY(int) functions. For instance, if you touch the screen with two fingers and want the position of the second finger, you would use

    x2 = getX(1);
    y2 = getY(1);
    

    getX() is the same as getX(0) and
    getY() is the same as getY(0)

    You can check out the documentation for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So after some trial and error, I think I have my math finally figured
After thinking that I finally figured git out, I'm now finding myself super-confused about
EDIT I have finally figured out the problem i have been having on my
I finally figured out the cause of my problem, but I cannot determine a
I finally figured out how to implement pg_search's multisearch feature. But I'm having trouble
Finally figured it out thanks to One Mad Monkey, but forgot quotes on my
I've been stuck on this for ever and I finally figured it out and
I'm new to pattern matching, having finally figured it out. I am stuck trying
After wasting some time to figure out what goes wrong, I finally have to
SOLVED: Crap... why is it always you figure something out right AFTER you finally

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.