龙preSS按钮事件处理函数 [英] Long Press Button Event Handler
问题描述
我看到几篇文章,如本<一个href="http://stackoverflow.com/questions/4402740/android-long-click-on-a-button-perform-actions">one描述如何处理一个长preSS事件与一个按钮。我可以按照下列指示,但我想知道是否有可能做到这一点我处理一个点击的方式相同。我办理了点击的方法是定义XML处理程序这样:
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" />
然后在code这样:
then in code as such:
public void btn_NextLiftClick(View vw_Current)
{...}
我确实看到了布尔属性longClickable中的XML,但我看不出哪里定义事件处理程序,以便... ???
I do see the boolean property longClickable in the xml but I don't see where to define an event handler so...???
TIA JB
推荐答案
通过XML你不能做到这一点。相反,使用:
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;
}
});
确认此code来后的setContentView()
被调用。
Make sure this code comes after setContentView()
has been called.
此外,请确保 longClickable
属性设置为true。
Also, make sure that the longClickable
property is set to true.
这篇关于龙preSS按钮事件处理函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!