I'm having some trouble with my litView
inside my viewFlipper
.
// GestureDetector
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// Right to left swipe
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
IconManager.INSTANCE.leftSwipe();
vf.setInAnimation(slideLeftIn);
vf.setOutAnimation(slideLeftOut);
vf.showNext();
System.out.println("SWIIINGG!!");
// Left to right swipe
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_TH开发者_如何学PythonRESHOLD_VELOCITY) {
IconManager.INSTANCE.rightSwipe();
vf.setInAnimation(slideRightIn);
vf.setOutAnimation(slideRightOut);
vf.showPrevious();
}
} catch (Exception e) {
// nothing
}
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Log.e("Item Click","Item Click");
Intent intentAgenda = new Intent (Activity_Main.this, AgendaSelected.class);
//intentAgenda.putExtra("LECTURE_NAME", homeAgendaListAdapter.getItemId(3));
startActivity(intentAgenda);
return super.onSingleTapConfirmed(e);
}
}
This code enables me to flip among the views in the flipper and scroll in the lists within the different flips. However, this makes my entire app clickable. Even if I singleTap
on a blank surface, it registers a click, and sends me to where the Intent intentAgenda = new Intent
wants to send me. This should only happen when I tap on an item within the listView
!
What can I do to get the listener on the specific lists to only listen "on the lists" and not the entire app? I believe that the problem lies within the public boolean onSingleTapConfirmed
, but I can't see it.
I have not tried the above but one solution that actually work is to create a new OnItemClickListener and then setOnItemClickListener(your item click listener) on your lists. That would be to not use single tap in your case but just create a new on itemclick listener like this but more stylish:
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Intent intentAgenda = new Intent (Activity_Main.this, AgendaSelected.class);
// // intentAgenda.putExtra("LECTURE_NAME", homeAgendaListAdapter.getItemId(3));
startActivity(intentAgenda);
}
});
If you want to create more lists you can create a new item click listener and just point every list to it.
Since the ViewFlipper containing the lists has the same gestureListener, everything within the viewflipper that is tapped will trigger the onSingleTapConfirmed() method.. Try registering the lists on a seperate gesturelistner aswell to handle the taps only :) Feels like the problem isn't in this codeblock but rather where the gestureListners etc is set.
精彩评论