Reputation: 2813
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
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
Reputation: 975
http://www.passsy.de/activity_with_multitouch_for_buttons/ could help you, what android version are you using ?
Upvotes: 2