I think you are expecting two different functions for Same image But you can achieve this concept by using the Click and Long press You cannot achieve with single touch I will suggest you to use this long press and single Click Example for this problem is.....I will explain for the single button you will repeat it for Other Five buttons....
but.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
detector = new GestureDetector(getApplicationContext(), new TouchDetector());
return false;
}
});
public class TouchDetector implements android.view.GestureDetector.OnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
}
You try this for Achieve your Logic But it's a simple Logic you can use this Logic also
public class MainActivity extends Activity {
GestureDetector detector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button but1 = (Button) findViewById(R.id.button1);
Button but2 = (Button) findViewById(R.id.button2);
Button but3 = (Button) findViewById(R.id.button3);
Button but4 = (Button) findViewById(R.id.button4);
Button but5 = (Button) findViewById(R.id.button5);
Button but6 = (Button) findViewById(R.id.button6);
but1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//Do here your Activity calling functions....
}
});
but.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
//Do your sound Logic here
return false;
}
});
// you just repeat this for all other Five buttons...
}
}