2021/2/3

在进入之后可以进行一些操作

package com.example.bookkeeping;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class FirstActivity extends AppCompatActivity implements View.OnClickListener{
    private MyDatabaseHelper dbHelper;
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);
        initUI2();
    }

    private void initUI2() {

        findViewById(R.id.button4).setOnClickListener(this);
        findViewById(R.id.button3).setOnClickListener(this);
        findViewById(R.id.button6).setOnClickListener(this);
        findViewById(R.id.button5).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button4://执行按钮4
                Intent intent =new Intent();
                intent.setClass(getApplicationContext(), jilu.class);
                this.startActivity(intent);
                break;

            case R.id.button3://执行按钮3
                Intent intent2 =new Intent();
                intent2.setClass(getApplicationContext(), chakan.class);
                this.startActivity(intent2);
                break;

            case R.id.button5://执行按钮5
                Intent intent3 =new Intent();
                intent3.setClass(getApplicationContext(), chazhao.class);
                this.startActivity(intent3);
                break;

            case R.id.button6://执行按钮6
                dbHelper=new MyDatabaseHelper(this,"zhangben.db",null,4);
                SQLiteDatabase db=dbHelper.getWritableDatabase();
                //删除所有

                db.delete("zhangben",null,null);
                Toast.makeText(FirstActivity.this, "全部删除", Toast.LENGTH_SHORT).show();
                //删除专业=软件工程
                //db.delete("TTList","专业=?",new String[]{"软件工程"});
                break;
        }
    }
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/a"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="128dp"
        android:layout_gravity="center"
        android:text="
菜单页面

"
        android:textColor="@android:color/holo_blue_dark"
        android:textSize="40dp" />

    <Button
        android:id="@+id/button3"
        android:layout_width="189dp"
        android:layout_height="wrap_content"
        android:text="查看账单
"
        android:layout_gravity="center"
        android:textSize="35dp"
        style="?android:attr/borderlessButtonStyle"/>

    <Button
        android:id="@+id/button4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="记一笔
"
        android:layout_gravity="center"
        android:textSize="35dp"
        style="?android:attr/borderlessButtonStyle"/>

    <Button
        android:id="@+id/button5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="按时间查看账单
"
        android:layout_gravity="center"
        android:textSize="35dp"
        style="?android:attr/borderlessButtonStyle"/>

    <Button
        android:id="@+id/button6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="清空"
        android:layout_gravity="center"
        android:textSize="35dp"
        style="?android:attr/borderlessButtonStyle"/>

</LinearLayout>
原文地址:https://www.cnblogs.com/qiangini/p/14865483.html