3.11
所花时间:1小时
代码量:47
博客篇:1
了解到的知识点
package com.example.myapplication; import static com.example.myapplication.R.*; import static com.example.myapplication.R.id.button3; import android.annotation.SuppressLint; import android.os.Bundle; import android.os.Handler; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import java.security.AccessController; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private TextView result; private Button button3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(layout.activity_main); result = findViewById(id.result); button3 = findViewById(id.button3); button3.setOnClickListener(new MyOnClickListener()); } class MyOnClickListener implements View.OnClickListener{ @Override public void onClick(View v) { result.setText("yes"); } }
设置button3的点击事件
先findViewById
再setOnClickListener
再重写onClick