星期二, 4月 14, 2009

The first step to implement tap and hold on Android

I'd like to implement tap and hold.

The first step is to distinguish "Tap and hold" from other touch screen actions. I was trying to achieve that by overriding onTouchEvent of a certain view, but it's almost impossible to do that since there are only four common actions trigger that function (ACTION_CANCEL, ACTION_DOWN, ACTION_MOVE, ACTION_UP). Therefore, I turn to look for some other solutions.

Finally, here is a easy way to do that.

RelativeLayout relativeLayout = new RelativeLayout (this);
setContentView(relativeLayout);
relativeLayout.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Log.d(this.getClass().getName(), "onLongClick()");
return true;
}
});

沒有留言: