David Brown
David Brown

Reputation: 4823

Long Click event firing on the Button Click in Android

I have heard that we can create the click event of the Button by holding it for a few moments in Android.

I want to use that functionality in my application.

Can anyone please tell me how to do that?

Thanks, david

Upvotes: 3

Views: 4461

Answers (1)

techi.services
techi.services

Reputation: 8533

Look at 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;
         }
     });
   }
}

Upvotes: 5

Related Questions