Long Press Button Event Handler

后端 未结 1 416
温柔的废话
温柔的废话 2021-01-05 19:25

I have seen several articles such as this one describing how to handle a long press event with a button. I can follow these directions but I am wondering if it is possible

相关标签:
1条回答
  • 2021-01-05 19:43

    You can't do this via XML. Instead, use:

    Button button = (Button) findViewById(R.id.btn_NextLift);
    
    button.setOnLongClickListener(new OnLongClickListener() { 
            @Override
            public boolean onLongClick(View v) {
                // TODO Auto-generated method stub
                return true;
            }
        });
    

    Make sure this code comes after setContentView() has been called.

    Also, make sure that the longClickable property is set to true.

    0 讨论(0)
提交回复
热议问题