zoukankan      html  css  js  c++  java
  • 2021.2.28 家庭记账本(3)

    一、今日学习内容

       今天完成了家庭记账本的修改账目

    <?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=" #855E42"
        tools:context=".UpdateActivity">
    
        <TextView
            android:id="@+id/id_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="116dp"
            android:layout_marginBottom="53dp"
            android:text="将要修改账目的序号:"
            android:textColor="#000000"
            android:textSize="25sp"
            app:layout_constraintBottom_toTopOf="@+id/id_edit_text"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
        <EditText
            android:id="@+id/id_edit_text"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginStart="32dp"
            android:layout_marginLeft="32dp"
            android:layout_marginEnd="32dp"
            android:layout_marginRight="32dp"
            android:layout_marginBottom="54dp"
            android:background="@drawable/bg_biankuang"
            android:hint="  序号可在'浏览所有账目'中查看"
            android:textColor="#ffc0cb"
            android:textSize="20sp"
            app:layout_constraintBottom_toTopOf="@+id/updatebutton"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/id_text_view" />
    
        <Button
            android:id="@+id/updatebutton"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="50dp"
            android:layout_marginLeft="50dp"
            android:layout_marginEnd="48dp"
            android:layout_marginRight="48dp"
            android:layout_marginBottom="275dp"
            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="@+id/guideline"
            app:layout_constraintTop_toBottomOf="@+id/id_edit_text" />
    
        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_begin="20dp" />
    
        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_begin="20dp" />
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    package com.example.bookkeeping;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
    
    import org.litepal.LitePal;
    
    import java.util.List;
    
    public class Update1Activity extends AppCompatActivity {
        private EditText etName, etDate, etOut1, etOut2, etIn1, etIn2;
        String name, date, out1, out2, in1, in2;
        Long id;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_update1);
            etName = (EditText) findViewById(R.id.name_edit_text);
            etDate = (EditText) findViewById(R.id.date_edit_text);
            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);
            Intent intent = this.getIntent();
            Money m2= (Money) intent.getSerializableExtra("money2");
            etName.setText(m2.getName());
            etDate.setText(m2.getDate());
            etOut1.setText(m2.getOut1());
            etOut2.setText(m2.getOut2());
            etIn1.setText(m2.getIn1());
            etIn2.setText(m2.getIn2());
            id=m2.getId();
    
            Button button1 = (Button) findViewById(R.id.update1button);
            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.update(id);
                }
    
            });
        }
    }

    二、遇到的问题

      页面的输入框大小总是固定不了

    三、明日计划

      明天继续完成家庭记账本

  • 相关阅读:
    [CF703D] Mishka and Interesting sum
    [CF1454F] Array Partition
    [CF13E] Holes
    [CF1110D] Jongmah
    [CF1204D2] Kirk and a Binary String
    [CF936B] Sleepy Game
    [CF546E] Soldier and Traveling
    [CF1025D] Recovering BST
    [CF598C] Nearest vectors
    [CF988E] Divisibility by 25
  • 原文地址:https://www.cnblogs.com/wmdww/p/14904658.html
Copyright © 2011-2022 走看看