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;
}
});
}
}
精彩评论