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 to do it the same way I handled a click. The way I handled a click was to define the handler in XML as such:
<Button
android:id="@+id/btn_NextLift"
...
android:onClick="btn_NextLiftClick" />
then in code as such:
public void btn_NextLiftClick(View vw_Current)
{...}
I do see the boolean property longClickable in the xml but I don't see where to define an event handler so...???
TIA JB
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With