在Android中,按钮点击时触发长按事件。

3

我听说在Android中,我们可以通过长按按钮来创建按钮的点击事件。

我想在我的应用程序中使用这个功能。

请问有人可以告诉我如何实现吗?

谢谢, 大卫

1个回答

5

看一下 View.OnLongClickListener

public class MyActivity extends Activity {
   protected void onCreate(Bundle icicle) {
     super.onCreate(icicle);

     setContentView(R.layout.content_layout_id);

     final Button button = (Button) findViewById(R.id.button_id);
     button.setOnLongClickListener(new View.OnLongClickListener() {
         public boolean onLongClick(View v) {
             // Perform action on click
             return true;
         }
     });
   }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接