在Android上的按钮单击中点击长按事件

Dav*_*own 3 android click button

我听说过我们可以通过在Android中暂存一下来创建Button的click事件.

我想在我的应用程序中使用该功能.

谁能告诉我怎么做?

谢谢,大卫

tec*_*ces 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;
         }
     });
   }
}
Run Code Online (Sandbox Code Playgroud)