ViewFlipper 内的 listView - 滚动问题

发布于 2024-10-17 18:44:34 字数 1961 浏览 6 评论 0原文

我的 viewFlipper 中的 litView 遇到了一些问题。

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

此代码使我能够在翻转器中的视图之间翻转,并在不同翻转的列表中滚动。然而,这使得我的整个应用程序可点击。即使我在空白表面上singleTap,它也会记录一次点击,并将我发送到IntentintentAgenda = new Intent想要发送给我的位置。仅当我点击 listView 中的项目时才会发生这种情况!

我该怎么做才能让特定列表上的侦听器仅侦听“列表上”而不是整个应用程序?我相信问题出在 public boolean onSingleTapConfirmed 中,但我看不到它。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫弦 2024-10-24 18:44:34

我没有尝试过上述方法,但实际有效的一种解决方案是创建一个新的 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);
        }
    });

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

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.

爱格式化 2024-10-24 18:44:34

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文