First, remove android:focusable="true"
and android:focusableInTouchMode="true"
from layout_button_sub
and layout_button_find
in your layout xml.
This prevents the first touch/click event from being consumed by a focus change.
Then, change your OnTouchListener
to an OnClickListener
:
private class mOnClickListener implements OnClickListener
{
Intent intent;
public void onClick(View v)
{
switch (v.getId())
{
case R.id.layout_button_sub:
intent = new Intent(AppActivity.this, Subs.class);
break;
case R.id.layout_button_find:
intent = new Intent(AppActivity.this, Find.class);
break;
}
if (intent != null)
{
startActivity(intent);
}
}
}
And set it as such for your LinearLayouts:
mOnClickListener listener = new mOnClickListener();
linearLayoutSubs.setOnClickListener(listener);
linearLayoutFind.setOnClickListener(listener);
The onTouch()
event fires on several MotionEvents: ACTION_DOWN
, ACTION_MOVE
, etc. Every time you "clicked" with an OnTouchListener
, the method was firing, at minimum, once when you put your finger down and once when you lifted your finger. Since your original onTouch()
method didn't account for the different actions, startActivity()
was being called for every touch event.