Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LongClick event also triggers Click event

I use onLongClick and onClick events of a button to get user inputs. Whenever; the user long click and triggers onLongClick event, the onClick event is also triggered. I couldn't find my problem. The code of two methods are shown in below:

@Override
    public void onClick(View v) {
        switch(((Button) v).getId())
        {
        case R.id.enter:
            EntertheNumber();
            break;
        case R.id.clear:
            CleartheNumber();
            break;
        case R.id.number_zero:
        case R.id.number_one:
        case R.id.number_two:
        case R.id.number_three:
        case R.id.number_four:
        case R.id.number_five:
        case R.id.number_six:
        case R.id.number_seven:
        case R.id.number_eight:
        case R.id.number_nine:
            AddtotheNumber(mEditor, (Button) v);
            break;
        }
@Override
    public boolean onLongClick(View view) {
        if(SMBGuesstheNumber.bDisplayFlagList)
        {
            theActiveButton = (Button) view;
            showDialog(R.id.display_flaglist);
        }
        return false;
    }

Actually, my project is Open Source. So, you can find all the code at http://code.google.com/p/guessthenumber/

Thank you.

like image 695
Ömer Avatar asked Apr 12 '09 18:04

Ömer


1 Answers

I'm not sure what order these events occur but the onLongClick handler returns a bool to indicate whether the event was handled. You should return true if you handled it so that other click events will not be called. I don't know if this will prevent prevent the onClick() from firing though.

You may also turn these events off and on using setClickable(boolean) and setLongClickable(boolean)

You can find this information and more about UI events here.

like image 177
Arnold Spence Avatar answered Oct 22 '22 01:10

Arnold Spence