Hassy31
Hassy31

Reputation: 2813

how to touch on two buttons at the same time in Android

I want to implement OnTouchEvent for two buttons and get MotionEvent.ACTION_MOVE function at same time.

I implemented onTouchEvent but doesn't work

    left = (Button)findViewById(R.id.button1);
    right = (Button)findViewById(R.id.button2);
    left.setOnTouchListener(this);
    right.setOnTouchListener(this);

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub

        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if(v.getId()==R.id.button1){
                Log.i("left", "moved!");
            }
            if(v.getId()==R.id.button2){
                Log.i("right", "move!");
            }
        }
        return false;
    }

in AndroidManifest.xml

<uses-feature android:name="android.hardware.touchscreen.multitouch"
           android:required="true" />

please help me to figure this out.

Upvotes: 2

Views: 1841

Answers (2)

H&#252;seyin Z.
H&#252;seyin Z.

Reputation: 836

Try this one:

      if (event.getAction() == MotionEvent.ACTION_DOWN) {
        if(v==left){
            Log.i("left", "moved!");
        }
        if(v == right){
            Log.i("right", "move!");
        }
    }

You should make left and right buttons be class members.

Edit: sorry may cause the same effect.

Upvotes: 0

dontcare
dontcare

Reputation: 975

http://www.passsy.de/activity_with_multitouch_for_buttons/ could help you, what android version are you using ?

Upvotes: 2

Related Questions