• <legend id='2Gwex'><style id='2Gwex'><dir id='2Gwex'><q id='2Gwex'></q></dir></style></legend>

      1. <i id='2Gwex'><tr id='2Gwex'><dt id='2Gwex'><q id='2Gwex'><span id='2Gwex'><b id='2Gwex'><form id='2Gwex'><ins id='2Gwex'></ins><ul id='2Gwex'></ul><sub id='2Gwex'></sub></form><legend id='2Gwex'></legend><bdo id='2Gwex'><pre id='2Gwex'><center id='2Gwex'></center></pre></bdo></b><th id='2Gwex'></th></span></q></dt></tr></i><div id='2Gwex'><tfoot id='2Gwex'></tfoot><dl id='2Gwex'><fieldset id='2Gwex'></fieldset></dl></div>

      2. <small id='2Gwex'></small><noframes id='2Gwex'>

          <bdo id='2Gwex'></bdo><ul id='2Gwex'></ul>
        <tfoot id='2Gwex'></tfoot>

      3. LongClick 事件发生得太快.如何增加触发它所需的点

        时间:2023-08-31
        <legend id='RDZ2G'><style id='RDZ2G'><dir id='RDZ2G'><q id='RDZ2G'></q></dir></style></legend>

            <tbody id='RDZ2G'></tbody>

          <small id='RDZ2G'></small><noframes id='RDZ2G'>

              <bdo id='RDZ2G'></bdo><ul id='RDZ2G'></ul>
                <tfoot id='RDZ2G'></tfoot>

                  <i id='RDZ2G'><tr id='RDZ2G'><dt id='RDZ2G'><q id='RDZ2G'><span id='RDZ2G'><b id='RDZ2G'><form id='RDZ2G'><ins id='RDZ2G'></ins><ul id='RDZ2G'></ul><sub id='RDZ2G'></sub></form><legend id='RDZ2G'></legend><bdo id='RDZ2G'><pre id='RDZ2G'><center id='RDZ2G'></center></pre></bdo></b><th id='RDZ2G'></th></span></q></dt></tr></i><div id='RDZ2G'><tfoot id='RDZ2G'></tfoot><dl id='RDZ2G'><fieldset id='RDZ2G'></fieldset></dl></div>
                  本文介绍了LongClick 事件发生得太快.如何增加触发它所需的点击时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在我正在处理的应用程序中,我要求用户必须单击 &在某个动作发生之前持有一个组件一段时间.

                  In an application I'm working on, I have the requirement that a user must click & hold a component for a period time before a certain action occurs.

                  我目前正在使用OnLongClickListener来监听longclick,但是我发现触发OnLongClick事件的点击时长太短了.

                  I'm currently using an OnLongClickListener to listen for the longclick, but I find that the length of a click to trigger the OnLongClick event is too short.

                  例如,假设 LongClick 事件在单击 400 毫秒后触发,但我希望用户必须单击 &在事件触发前保持 1200ms.

                  For example, let's say the LongClick event triggers after a 400ms click, but I want the user to have to click & hold for 1200ms before the event triggers.

                  有什么方法可以将 LongClick 事件配置为需要更长的点击时间?
                  或者是否有其他构造可以让我听到更长的点击?

                  Is there any way I can configure the LongClick event to require a longer click?
                  Or is there perhaps another construct that would allow me to listen for longer clicks?

                  推荐答案

                  onLongClick事件不能改变定时器,由android自己管理.

                  It is not possible to change the timer on the onLongClick event, it is managed by android itself.

                  可以使用 .setOnTouchListener().

                  What is possible is to use .setOnTouchListener().

                  然后在 MotionEvent 为 ACTION_DOWN 时注册.
                  请注意变量中的当前时间.
                  然后当一个带有 ACTION_UP 的 MotionEvent 被注册并且 current_time - actionDown 时间 > 1200 毫秒时,然后做一些事情.

                  Then register when the MotionEvent is a ACTION_DOWN.
                  Note the current time in a variable.
                  Then when a MotionEvent with ACTION_UP is registered and the current_time - actionDown time > 1200 ms then do something.

                  差不多:

                  Button button = new Button();
                  long then = 0;
                      button.setOnTouchListener(new OnTouchListener() {
                  
                          @Override
                          public boolean onTouch(View v, MotionEvent event) {
                              if(event.getAction() == MotionEvent.ACTION_DOWN){
                                  then = (Long) System.currentTimeMillis();
                              }
                              else if(event.getAction() == MotionEvent.ACTION_UP){
                                  if(((Long) System.currentTimeMillis() - then) > 1200){
                                      return true;
                                  }
                              }
                              return false;
                          }
                      })
                  

                  这篇关于LongClick 事件发生得太快.如何增加触发它所需的点击时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:onTouchEvent()中如何区分移动和点击? 下一篇:jQuery 是否保留触摸事件属性?

                  相关文章

                  最新文章

                  <tfoot id='d6lVU'></tfoot>

                    <small id='d6lVU'></small><noframes id='d6lVU'>

                    • <bdo id='d6lVU'></bdo><ul id='d6lVU'></ul>
                    <legend id='d6lVU'><style id='d6lVU'><dir id='d6lVU'><q id='d6lVU'></q></dir></style></legend>
                    <i id='d6lVU'><tr id='d6lVU'><dt id='d6lVU'><q id='d6lVU'><span id='d6lVU'><b id='d6lVU'><form id='d6lVU'><ins id='d6lVU'></ins><ul id='d6lVU'></ul><sub id='d6lVU'></sub></form><legend id='d6lVU'></legend><bdo id='d6lVU'><pre id='d6lVU'><center id='d6lVU'></center></pre></bdo></b><th id='d6lVU'></th></span></q></dt></tr></i><div id='d6lVU'><tfoot id='d6lVU'></tfoot><dl id='d6lVU'><fieldset id='d6lVU'></fieldset></dl></div>