Question

My app has 12 buttons with sounds, but only one button can be pressed at once. What do I need to do to enable multitouch in my app?

Here's some code of my Activity:

import java.io.IOException;
public class MyActivity extends Activity implements View.OnTouchListener {

    Button button1, button2, button3;
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    button1 = (Button) findViewById(R.id.button);
    button2 = (Button) findViewById(R.id.button2);
    button3 = (Button) findViewById(R.id.button3);


    Button beatSound1 = (Button)this.findViewById(R.id.button4);
    beatSound1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            playSound(beat2);
            Log.d("MY", "COW");
        }
    });
    Button beatSound2 = (Button)this.findViewById(R.id.button5);
    beatSound2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            playSound(beat3);
            Log.d("MY", "COW");
        }
    });
Was it helpful?

Solution

In your case, as far as i can see, you're working with only one Thread. That's your problem, I guess that your function playSound() is also in the same activity, you can't execute multiple calls of this function at once without multithreading (which can be done with AsyncTask).

Note that multitouching is not part of developers job, there is no way to enable more touching capability (this is part of hardware). But usually you can use 10~ fingers at once.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top