zoukankan      html  css  js  c++  java
  • 家庭记账本day7

    查看账单功能实现

    showActivity文件代码:

     1 package com.example.keep;
     2 
     3 import android.database.Cursor;
     4 import android.database.sqlite.SQLiteDatabase;
     5 import android.os.Bundle;
     6 import android.widget.TextView;
     7 
     8 import androidx.annotation.Nullable;
     9 import androidx.appcompat.app.AppCompatActivity;
    10 
    11 import static com.example.keep.Constants.TABLE_NAME;
    12 
    13 public class ShowActivity extends AppCompatActivity {
    14     private DatabaseHelper myHelper;
    15     public SQLiteDatabase db;
    16     String str="";
    17 
    18     protected void onCreate(@Nullable Bundle savedInstanceState) {
    19         super.onCreate(savedInstanceState);
    20         setContentView(R.layout.activity_show);
    21         final TextView tv=(TextView)findViewById(R.id.allshow);
    22         myHelper=new DatabaseHelper(this);
    23         SQLiteDatabase db=myHelper.getWritableDatabase();
    24         Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, null);//读取数据库所有信息
    25         if(cursor.moveToFirst()){
    26             do{
    27                 String in_out=cursor.getString(cursor.getColumnIndex("in_out"));
    28                 String money=cursor.getString(cursor.getColumnIndex("money"));
    29                 String date=cursor.getString(cursor.getColumnIndex("date"));
    30                 String type=cursor.getString(cursor.getColumnIndex("type"));
    31                 String way=cursor.getString(cursor.getColumnIndex("way"));
    32                /* Log.d("chakan","盈亏为:"+ye);
    33                 Log.d("chakan","原因为:"+why);
    34                 Log.d("chakan","金额为:"+money);
    35                 Log.d("chakan","时间为:"+time);*/
    36                 str+=in_out+"		"+ money+"元		"+date+"		"+type+"			"+way+"
    ";//将数据库信息存到str中并换行
    37             }while (cursor.moveToNext());
    38         }
    39         cursor.close();
    40         tv.setText(str);//打印信息
    41     }
    42 }

    activity_show.xml文件代码:

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     xmlns:tools="http://schemas.android.com/tools"
     4     android:orientation="vertical"
     5     android:layout_width="match_parent"
     6     android:layout_height="match_parent"
     7     tools:context=".ShowActivity"
     8     android:background="@mipmap/bj_2">
     9     <!--标题栏-->
    10     <include layout="@layout/titlebar" />
    11     <TextView
    12         android:layout_width="wrap_content"
    13         android:layout_height="wrap_content"
    14         android:textSize="20sp"
    15         android:text="           金额        日期       类别    支付方式"/>
    16     <TextView
    17         android:id="@+id/allshow"
    18         android:layout_width="match_parent"
    19         android:layout_height="wrap_content"
    20         android:layout_marginTop="25dp"
    21         android:textSize="20sp" />
    22 
    23 </LinearLayout>

    界面展示:

  • 相关阅读:
    STM32的串口DMA收发以及双缓冲区的实现
    平衡二叉树
    二叉树的深度
    3D数学基础(四)四元数和欧拉角
    3D数学基础(三)矩阵
    3D数学基础(二)向量
    3D数学基础(一)Unity坐标系
    快速学会开发微信小程序
    苦逼的程序员
    开通博客,在这个年末,重新开始。
  • 原文地址:https://www.cnblogs.com/znjy/p/14905493.html
Copyright © 2011-2022 走看看