Java – Android – Can I use setOnLongClickListener and setOnClickListener for the same button?

Android – Can I use setOnLongClickListener and setOnClickListener for the same button?… here is a solution to the problem.

Android – Can I use setOnLongClickListener and setOnClickListener for the same button?

Can I really use these setOnLongClickListener and setOnClickListener for the same button?
Because if I press and hold the button, both longclick and normal click are executed, I don’t 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
                  }
              });

Solution

Return TRUE in your onLongClick method to use the event.

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

Related Problems and Solutions