本文介绍了Android的 - 我可以使用setOnLongClickListener和setOnClickListener为相同的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以真正使用这些setOnLongClickListener和setOnClickListener为相同的按钮?
因为如果我长按一下按钮都longclick和正常的点击将被执行,我不知道为什么。我真的能做到这一点?
请帮我:)

  readDbButton.setOnLongClickListener(
                      新View.OnLongClickListener(){
                          公共布尔onLongClick(查看视图){
                                //做一点事
                              返回false;
                          }
                      }
              );              readDbButton.setOnClickListener(
              新View.OnClickListener()
              {
                  公共无效的onClick(查看视图)
                  {
                        //做别的事情
                  }
              });


解决方案

返回你的 onLongClick 方法true,这样该事件将被消耗掉。

  readDbButton.setOnLongClickListener(
                      新View.OnLongClickListener(){
                          公共布尔onLongClick(查看视图){
                                //做一点事
                              返回true;
                          }
                      }
              );

Can I really use these setOnLongClickListener and setOnClickListener for same button?Because if I long click the button both longclick and normal click will be executed and I dont know why. Can I really do this?Please help me:)

              readDbButton.setOnLongClickListener(
                      new View.OnLongClickListener() {
                          public boolean onLongClick(View view) {
                                //do something
                              return false;
                          }
                      }
              );

              readDbButton.setOnClickListener(
              new View.OnClickListener()
              {
                  public void onClick(View view)
                  {
                        //Do something else
                  }
              });
解决方案

return TRUE in your onLongClick method so that the event will be consumed.

  readDbButton.setOnLongClickListener(
                      new View.OnLongClickListener() {
                          public boolean onLongClick(View view) {
                                //do something
                              return true;
                          }
                      }
              );

这篇关于Android的 - 我可以使用setOnLongClickListener和setOnClickListener为相同的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 22:16