Skip to content

Instantly share code, notes, and snippets.

@wowiwo1
Last active September 15, 2015 04:47
Show Gist options
  • Save wowiwo1/a9f25c4deed96674b8bc to your computer and use it in GitHub Desktop.
Save wowiwo1/a9f25c4deed96674b8bc to your computer and use it in GitHub Desktop.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView tv1 = (TextView) findViewById(R.id.tv1);
final TextView tv2 = (TextView) findViewById(R.id.tv2);
final TextView tv3 = (TextView) findViewById(R.id.tv3);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl);
rl.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
for (int i = 0; i < event.getPointerCount(); i++)
{
int x = (int) event.getX(i);
int y = (int) event.getY(i);
int id = event.getPointerId(i);
int actionIndex = event.getActionIndex();
String actionString = Integer.toString(event.getActionMasked());
if (event.getActionMasked() == MotionEvent.ACTION_MOVE)
continue;
switch (i)
{
case 0:
tv1.setText(actionString + " " + actionIndex + " " + id + "\n");
break;
case 1:
tv2.setText(actionString + " " + actionIndex + " " + id + "\n");
break;
case 2:
tv3.setText(actionString + " " + actionIndex + " " + id + "\n");
break;
default:
break;
}
}
return false; // true일 때 event consumption 발생, onclick onlongclick 등등 호출 안됨
}
});
rl.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
tv3.setText("setOnLongClickListener called");
return false; // true일 시 onclick 호출 안됨
}
});
rl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv3.setText("onClick called");
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment