2021年2月23日 记账本开发06

今天完成了详情页面的编写以及删除和取消工作,明天完善更改工作。

SelectAct:

package bjfu.it.sun.cashbook;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class SelectAct extends Activity implements View.OnClickListener  {
    private Button s_delete,s_back;
    private TextView content,time,coast;
    private CashDB cashDB;
    private SQLiteDatabase dbWrite;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select); //加载视图
        //System .out.println(getIntent() .getIntExtra(CashDB.ID ,0) ) ;
        s_delete=findViewById(R.id.del ) ;//按钮找id
        s_back=findViewById(R.id.cancel) ;
        content = (TextView) findViewById(R.id.s_content );
        time = (TextView) findViewById(R.id.s_time );
        coast = (TextView) findViewById(R.id.s_time );

        cashDB =new CashDB(this);//数据库初始化
        dbWrite =cashDB.getWritableDatabase() ;//获得写的权限
/*
        s_back .setOnClickListener(this) ;//加上监听事件
        s_delete .setOnClickListener(this) ;
*/
        //展示内容
        content .setText(getIntent().getStringExtra(CashDB .CONTENT) );//内容
        time .setText(getIntent().getStringExtra(CashDB .TIME) );//花费
        coast .setText(getIntent().getStringExtra(CashDB .COAST ) );//时间

    }


    @Override
    public void onClick(View v) {
        switch (v.getId() ){
            case R.id.del :
                deleteDate();
                finish();

                break;
            case R.id.cancel :
                finish();
                break;
        }
    }

    public void deleteDate(){
        System .out.println(getIntent() .getIntExtra(CashDB.ID ,0) ) ;
        dbWrite .delete(CashDB.TABLE_NAME ,"_id="+getIntent() .getIntExtra(CashDB .ID ,0),null );
    }
}
<?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="wrap_content"
    tools:context=".SelectAct">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent">

        <LinearLayout
            android:id="@+id/linearLayout3"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <TextView
                android:id="@+id/s_content"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:text="TextView" />

            <TextView
                android:id="@+id/s_coast"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:text="TextView" />

            <TextView
                android:id="@+id/s_time"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:text="TextView" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal">

            <Button
                android:id="@+id/submit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="修改" />

            <Button
                android:id="@+id/del"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="onClick"
                android:text="删除" />

            <Button
                android:id="@+id/cancel"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="onClick"
                android:text="返回" />

        </LinearLayout>
    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

 

posted @ 2021-02-23 23:36  yasai  阅读(33)  评论(0编辑  收藏  举报