我试图在OnTouchListner上设置spinner。可以在自定义视图上调用它,但不能在微调器上调用。

也尝试使用MotionEvent.ACTION_DOWN。代码不适用于Spinner,但
在CustomView-上工作

view.setOnTouchListener(new View.OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if(event.getAction()==MotionEvent.ACTION_DOWN){
                    pos=finalI;
                    Log.e("In View CLicked", "Clicked " + finalI);
                    loadVisitData();
                }

                return false;
            }
        });


代码不适用于Spinner-

spinDist.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if(event.getAction()==MotionEvent.ACTION_DOWN) {
                Log.e("Touch","OnTouch");
                }
                Toast.makeText ( EnquiryForm.this, "test", Toast.LENGTH_SHORT ).show();
                Log.e("Touch","OnTouch");
                return false;
            }
        });

最佳答案

通过覆盖Spinner方法为setOnTouchListener()尝试此操作,

spinDist.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if(event.getAction()==MotionEvent.ACTION_UP){
                    Toast.makeText ( EnquiryForm.this, "test", Toast.LENGTH_SHORT ).show();
              }
              return false;
          }
   });

关于android - 微调器OnTouchListener,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56852510/

10-12 06:08