开发者

Long Click event firing on the Button Click in Android

I have heard that we can create the click开发者_如何学JAVA 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


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;
         }
     });
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜