一、今日学习内容
今天完成了家庭记账本的记账的相关页面
package com.example.bookkeeping; import androidx.appcompat.app.AppCompatActivity; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import org.litepal.LitePal; import org.litepal.tablemanager.Connector; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; public class AddActivity extends AppCompatActivity { private EditText etName, etDate, etOut1, etOut2, etIn1, etIn2; String name, date, out1, out2, in1, in2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add); Connector.getDatabase(); etName = (EditText) findViewById(R.id.name_edit_text); etDate = (EditText) findViewById(R.id.date_edit_text); etDate.setText(getDate()); etOut1 = (EditText) findViewById(R.id.out1_edit_text); etOut2 = (EditText) findViewById(R.id.out2_edit_text); etIn1 = (EditText) findViewById(R.id.in1_edit_text); etIn2 = (EditText) findViewById(R.id.in2_edit_text); Button button1 = (Button) findViewById(R.id.addbutton); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { LitePal.getDatabase(); name = etName.getText().toString().trim(); date = etDate.getText().toString().trim(); out1 = etOut1.getText().toString().trim(); out2 = etOut2.getText().toString().trim(); in1 = etIn1.getText().toString().trim(); in2 = etIn2.getText().toString().trim(); Money m = new Money(); m.setName(name); m.setDate(date); m.setOut1(out1); m.setOut2(out2); m.setIn1(in1); m.setIn2(in2); m.save(); if (m.save()) { Toast.makeText(AddActivity.this, "保存成功", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(AddActivity.this, "保存失败", Toast.LENGTH_SHORT).show(); } } }); } private String getDate() { SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd"); return date_format.format(new Date()); } }
<?xml version="1.0" encoding="utf-8"?> <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" android:background="@drawable/main_bg" tools:context=".AddActivity"> <TextView android:id="@+id/name_text_view" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginStart="40dp" android:layout_marginLeft="40dp" android:layout_marginTop="108dp" android:layout_marginEnd="13dp" android:layout_marginRight="13dp" android:layout_marginBottom="94dp" android:inputType="textPersonName" android:text="记录人姓名:" android:textColor="#000000" android:textSize="25sp" app:layout_constraintBottom_toTopOf="@+id/out1_edit_text" app:layout_constraintEnd_toStartOf="@+id/name_edit_text" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <EditText android:id="@+id/name_edit_text" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginTop="101dp" android:layout_marginEnd="52dp" android:layout_marginRight="52dp" android:layout_marginBottom="247dp" android:background="@drawable/bg_biankuang" android:textColor="#ffc0cb" android:textSize="30sp" app:layout_constraintBottom_toTopOf="@+id/in1_edit_text" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/name_text_view" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/date_text_view" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginStart="7dp" android:layout_marginLeft="7dp" android:layout_marginTop="1dp" android:layout_marginEnd="7dp" android:layout_marginRight="7dp" android:layout_marginBottom="2dp" android:text="日期:" android:textColor="#000000" android:textSize="25sp" app:layout_constraintBottom_toBottomOf="@+id/date_edit_text" app:layout_constraintEnd_toStartOf="@+id/name_edit_text" app:layout_constraintStart_toStartOf="@+id/out1_text_view" app:layout_constraintTop_toBottomOf="@+id/name_text_view" /> <EditText android:id="@+id/date_edit_text" android:layout_width="203dp" android:layout_height="0dp" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" android:layout_marginBottom="44dp" android:background="@drawable/bg_biankuang" android:textColor="#ffc0cb" android:textSize="30sp" app:layout_constraintBottom_toTopOf="@+id/out1_text_view" app:layout_constraintEnd_toEndOf="@+id/name_edit_text" app:layout_constraintTop_toBottomOf="@+id/name_text_view" /> <TextView android:id="@+id/out1_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="33dp" android:layout_marginLeft="33dp" android:layout_marginEnd="8dp" android:layout_marginRight="8dp" android:layout_marginBottom="43dp" android:text="支出金额:" android:textColor="#000000" android:textSize="25sp" app:layout_constraintBottom_toTopOf="@+id/out2_text_view" app:layout_constraintEnd_toStartOf="@+id/out1_edit_text" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/date_edit_text" /> <EditText android:id="@+id/out1_edit_text" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginEnd="52dp" android:layout_marginRight="52dp" android:layout_marginBottom="26dp" android:background="@drawable/bg_biankuang" android:textColor="#ffc0cb" android:textSize="30sp" app:layout_constraintBottom_toTopOf="@+id/out2_edit_text" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/out1_text_view" app:layout_constraintTop_toBottomOf="@+id/name_text_view" /> <TextView android:id="@+id/out2_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="40dp" android:layout_marginLeft="40dp" android:layout_marginEnd="5dp" android:layout_marginRight="5dp" android:layout_marginBottom="37dp" android:text="支出项目:" android:textColor="#000000" android:textSize="25sp" app:layout_constraintBottom_toTopOf="@+id/in1_text_view" app:layout_constraintEnd_toStartOf="@+id/out2_edit_text" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/out1_text_view" /> <EditText android:id="@+id/out2_edit_text" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginEnd="51dp" android:layout_marginRight="51dp" android:layout_marginBottom="14dp" android:background="@drawable/bg_biankuang" android:textColor="#ffc0cb" android:textSize="30sp" app:layout_constraintBottom_toTopOf="@+id/in1_edit_text" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/out2_text_view" app:layout_constraintTop_toBottomOf="@+id/out1_edit_text" /> <TextView android:id="@+id/in1_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="33dp" android:layout_marginLeft="33dp" android:layout_marginEnd="7dp" android:layout_marginRight="7dp" android:layout_marginBottom="39dp" android:text="收入金额:" android:textColor="#000000" android:textSize="25sp" app:layout_constraintBottom_toTopOf="@+id/in2_text_view" app:layout_constraintEnd_toStartOf="@+id/in1_edit_text" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/out2_text_view" /> <EditText android:id="@+id/in1_edit_text" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginEnd="49dp" android:layout_marginRight="49dp" android:layout_marginBottom="283dp" android:background="@drawable/bg_biankuang" android:textColor="#ffc0cb" android:textSize="30sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/in1_text_view" app:layout_constraintTop_toBottomOf="@+id/name_edit_text" /> <TextView android:id="@+id/in2_text_view" android:layout_width="155dp" android:layout_height="0dp" android:layout_marginStart="40dp" android:layout_marginLeft="40dp" android:layout_marginBottom="50dp" android:text="收入项目:" android:textColor="#000000" android:textSize="25sp" app:layout_constraintBottom_toTopOf="@+id/addbutton" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/in1_text_view" /> <EditText android:id="@+id/in2_edit_text" android:layout_width="183dp" android:layout_height="57dp" android:layout_marginEnd="1dp" android:layout_marginRight="1dp" android:layout_marginBottom="200dp" android:background="@drawable/bg_biankuang" android:textColor="#ffc0cb" android:textSize="30sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="@+id/out1_edit_text" app:layout_constraintStart_toStartOf="@+id/in1_edit_text" app:layout_constraintTop_toBottomOf="@+id/in1_edit_text" /> <Button android:id="@+id/addbutton" android:layout_width="0dp" android:layout_height="0dp" android:layout_gravity="center_horizontal" android:layout_marginStart="73dp" android:layout_marginLeft="73dp" android:layout_marginEnd="73dp" android:layout_marginRight="73dp" android:layout_marginBottom="97dp" android:background="@drawable/btn_all_shape" android:gravity="center" android:text="保存" android:textColor="#000000" android:textSize="25sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/in2_text_view" /> </androidx.constraintlayout.widget.ConstraintLayout>
二、遇到的问题
没有遇到问题
三、明日计划
明天继续完成家庭小账本