实现按钮的长按监听(聂同学的作业)
布局文件:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=“.MainActivity”>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="长按按钮"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Mainactivity:
package com.example.onlongclickllstener;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android