gpt4 book ai didi

android - Android 中的 Button Click 上的 Long Click 事件触发

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:00 24 4
gpt4 key购买 nike

听说在Android中我们可以通过按住几秒钟来创建Button的点击事件。

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

谁能告诉我该怎么做?

谢谢,大卫

最佳答案

查看 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;
}
});
}
}

关于android - Android 中的 Button Click 上的 Long Click 事件触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4476675/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com