2

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_THRESHOLD_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.

4

2 回答 2

1

我没有尝试过上述方法,但一种实际可行的解决方案是在列表中创建一个新的 OnItemClickListener,然后 setOnItemClickListener(您的项目单击侦听器)。那就是在您的情况下不使用单击,而只是像这样在 itemclick 上创建一个新的侦听器,但更时尚:

    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);
        }
    });

如果您想创建更多列表,您可以创建一个新的项目单击侦听器并将每个列表指向它。

于 2011-02-18T13:30:26.470 回答
1

由于包含列表的 ViewFlipper 具有相同的手势侦听器,因此在 viewflipper 中被点击的所有内容都将触发 onSingleTapConfirmed() 方法。尝试在单独的手势列表中注册列表以仅处理点击:) 感觉问题不在于在这个代码块中,而不是在设置gestureListners等的地方。

于 2011-02-18T13:04:06.047 回答