I have a view that need to process onTouch gestures and onClick events. What is the proper way to achieve this?
I have an onTouchListener and
I've been able to implement OnClick and OnTouch together in a custom keyboard I'm building. You can take a look at this code and modify it according to your context since you didn't include a code sample to work from.
If you post a sample of your code I can modify this sample of mine to accomplish the same outcome for your use. Context is everything when it comes to Android Development. Take a look at this code snippet and see if it helps. Otherwise post a sample of your own and I'll make the modifications and reply back.
View DefaultphaseLay() {
LinearLayout mViewFirstPhase = (LinearLayout) getLayoutInflater().inflate(R.layout.layout_default_phase, parent);
ksOne_btn_LiLay = (LinearLayout) mViewFirstPhase.findViewById(R.id.ksOne_btn_LiLay);
ksOne_btn = (Button) mViewFirstPhase.findViewById(R.id.ksOne_btn);
ksOne_btn.setOnClickListener(mCorkyListener);
ksOne_btn.setFocusableInTouchMode(true);
ksOne_btn.setFocusable(true);
ksOne_btn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
playClick(keyCode);
//v.startAnimation(animScale);
//key_sound.start();
xkeys_lay.setVisibility(View.GONE);
numkeys_lay.setVisibility(View.GONE);
if (Constants.HapticFeedbackConstant) {
myVib.vibrate(Constants.vibration_duration);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
ksOne_btn.setFocusable(false); //Check This Added This In Attempt to Kill Selector on Action_Up
//playClick(-100);
//key_sound.pause();
}
return false;
}
});
ChangeKeyBackgroundMehods.initChange_Key_Background(ksOne_btn_LiLay);
ChangeFontStyle.initChange_fontStyle(ksOne_btn, getApplicationContext());
ChangeFont_size.initChange_fontSize(ksOne_btn, getApplicationContext());
This works for the context of type alpha or numerical output, if the event is looking to send or consume some other context it would need to be modified.