Long click on button click on button

I heard that we can create a Button click event by holding it for several seconds in Android.

I want to use this functionality in my application.

Can anyone tell me how to do this?

Thanks David

+3
source share
1 answer

Take a look 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;
         }
     });
   }
}
+5
source

Source: https://habr.com/ru/post/1780987/


All Articles