Java Android-从2个独立的OnTouchListener检索变量

Java Android-从2个独立的OnTouchListener检索变量,java,android,Java,Android,我目前有两个不同的onTouchListener对象,每个对象覆盖屏幕的一侧。我希望用户同时触摸两侧,并计算两次触摸之间的时间差。到目前为止,我已经设置了两个onTouchListener对象,并在每个对象中定义了所需的变量。但是,我很难找到这两个变量之间的差异,因为它们在不同的onTouchListener对象中使用。这就是我迄今为止所尝试的: .java文件 public class Prompt5 extends Activity { long presstimeL1;

我目前有两个不同的
onTouchListener
对象,每个对象覆盖屏幕的一侧。我希望用户同时触摸两侧,并计算两次触摸之间的时间差。到目前为止,我已经设置了两个
onTouchListener
对象,并在每个对象中定义了所需的变量。但是,我很难找到这两个变量之间的差异,因为它们在不同的
onTouchListener
对象中使用。这就是我迄今为止所尝试的:

.java
文件

public class Prompt5 extends Activity {

    long presstimeL1;
    long presstimeR1;

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_prompt5);

            touchLayoutL.setOnTouchListener(new View.OnTouchListener(){
                @Override
                public boolean onTouch(View v, MotionEvent event){

                    //More code..

                    //Set the value of the variable
                    presstimeL1 = System.currentTimeMillis();

                return true;
                }
            });

            touchLayoutR.setOnTouchListener(new View.OnTouchListener(){
                @Override
                public boolean onTouch(View v, MotionEvent event){

                    //More code..

                    //Set the value of the variable
                    presstimeR1 = System.currentTimeMillis();

                return true;
                }
            });

    //Somehow find the difference between presstimeL1 and presstimeR1
    //The code below does not work because both presstimeL1 and presstimeR1 are 0 in this case
    long difference = presstimeL1 - presstimeR1;
如图所示,
touchLayoutL
覆盖屏幕左侧,
touchLayoutR
覆盖屏幕右侧,
按Timel1
从屏幕左侧获取系统时间,
按Timer1
从屏幕右侧获取时间


如您所见,我的目标是获得在不同的
onTouchListener
对象中使用的两个变量之间的差异。

Put
next.setText(String.valueOf(presstimeL1))在你的听力中他确实做到了。。这个问题真的没有意义sense@blackbelt在第二段代码中,但不是第一段代码,我认为这是他正在努力实现的。但我可能是错的,因为我同意这是令人困惑的,那么您下一步在哪里调用这个。setText(String.valueOf(presstimeL1))?在调用onTouch之后,应该以某种方式调用它,否则“next”将始终显示值0。它不起作用,因为它位于
onCreate()
中,因此它仅在首次创建活动时运行。用第二种方法做,然后解释/张贴这种方法不起作用的地方