指针的问题! (安卓) [英] Pointer problems! (Android)

查看:97
本文介绍了指针的问题! (安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,在onTouch方法多个指针。 所有指针都与一个布尔值相关联的,真要是下来,否则为false了。如果一个指针从真变成假时,将不会影响其他布尔值是非常重要的。

I've got a problem with multiple pointers in an onTouch method. All pointers are associated with a boolean value, true if down and false if up. It is very important that if one pointer changes from true to false it will not affect the other boolean values.

我遇到的问题是,例如当指针1和2是向下指向2上升(变更为false),指针1也是在迭代更改为false。这是因为该指针ID被改变指针计数的变化时。

The problem I'm having is the when for example pointer 1 and 2 are down and pointer 2 goes up (changes to false), pointer 1 is also in that iteration changed to false. This is because the pointers IDs are changing when the pointer count changes.

你有如何解决我遇到的问题有什么建议?

Do you have any suggestions of how to fix the problems I am having?

这是在code:

public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    int action = (event.getAction() & MotionEvent.ACTION_MASK);
    int pointCount = event.getPointerCount();

    for (int i = 0; i < pointCount; i++) {
        int id = event.getPointerId(i);


        if (id < MAX_NUMBER_OF_POINT) {
            Log.d(TAG, String.valueOf(id));
            xA[id] = (int) event.getX(i);
            yA[id] = (int) event.getY(i);

            if ((action == MotionEvent.ACTION_DOWN)
                    || (action == MotionEvent.ACTION_POINTER_DOWN)
                    || (action == MotionEvent.ACTION_MOVE)) {
                touching[id] = true;
            } else {
                Log.e(TAG, "i: " + String.valueOf(i));
                Log.e(TAG, "id: " + String.valueOf(id));
                touching[id] = false;
            }
        }
    }


    for (int i2 = 0; i2 < 5; i2++) {
        if (touching[i2] == false) {
            // Log.d(TAG, "Was Here" + String.valueOf(i2));
            xA[i2] = 0;
            yA[i2] = 0;
        }
    }

    x1 = xA[0];
    x2 = xA[1];
    x3 = xA[2];
    x4 = xA[3];

    y1 = yA[0];
    y2 = yA[1];
    y3 = yA[2];
    y4 = yA[3];

return true;
}

谢谢!

推荐答案

我觉得有一个ID的东西的一点是,让你有由引用它一致的名称。如果ID是变化的指针数,也许识别另一个系统被调用。你可以做pointerIDs的/一个数组,被引用的单独更新指针计数。

I think the point of having an id for something is so that you have a consistent name by which to reference it. If the id is changing with the pointer count, perhaps another system of identification is called for. You could make an array of pointerIDs that gets referenced/updated independently of the pointer count.

这篇关于指针的问题! (安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆