您可以尝试使用Touch Listener执行此操作.
尝试:
Handler handler = new Handler();
b.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
switch (arg1.getAction()) {
case MotionEvent.ACTION_DOWN:
handler.postDelayed(run, 5000/* OR the amount of time you want */);
break;
case MotionEvent.ACTION_CANCEL:
handler.removeCallbacks(run);
break;
case MotionEvent.ACTION_UP:
handler.removeCallbacks(run);
break;
}
return true;
}
});
其中b是您要长按的视图.
Runnable运行如下
Runnable run = new Runnable() {
@Override
public void run() {
// Your code to run on long click
}
};
希望能帮助到你… :)