安卓:长点击一个按钮 - >执行操作 [英] Android: long click on a button -> perform actions
问题描述
欲使用相同的按钮来执行2不同的方法。 一种方法中,当用户点击单个它和第二方法(不同的),当用户长点击它
I want to use the same button to perform 2 different methods. One method when user single clicks it and a second method (different) when the user LONG clicks it.
我用这个为单短按一下(这伟大工程):
I use this for the single short click (which works great):
Button downSelected = (Button) findViewById(R.id.downSelected);
downSelected.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
method();
}
}
});
我试图添加longClickListener,但没有奏效。
I've tried to add a longClickListener but it didn't work.
鸭preciate关于如何解决这个任何想法。
Appreciate any ideas on how to solve this.
谢谢!
推荐答案
我以前做过,我只是用:
I've done it before, I just used:
down.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
return true;
}
});
每文档:
公共无效setOnLongClickListener (View.OnLongClickListener L)
public void setOnLongClickListener (View.OnLongClickListener l)
自:API级别1注册一个回调 当这种观点是被调用 点击并举行。如果这种观点是不 长的点击,它变长 点击。
Since: API Level 1 Register a callback to be invoked when this view is clicked and held. If this view is not long clickable, it becomes long clickable.
请注意,它需要返回一个布尔值,这应该工作。
Notice that it requires to return a boolean, this should work.
这篇关于安卓:长点击一个按钮 - >执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!