使用android studio编写个人理财要求提供登录界面给用户 3. 要求有界面让用户输入每天的收入和支出(包括但不限于以下字段:项目名称,金额,录入时间,类别(信用卡/现金) 4. 可以对某笔记录添加文字或者照片备注。 5. 支持按照每日,每月,每年进行统计、查询。 6. 以上内容要求记入SQLITE或者文件系统中,APP重启后不丢失。的代码

时间: 2023-06-19 20:04:08 浏览: 43
以下是一个简单的 Android Studio 代码示例,实现了您的要求: 首先是登录界面的布局文件 `activity_login.xml`: ```xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:id="@+id/et_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入用户名" android:padding="16dp"/> <EditText android:id="@+id/et_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入密码" android:inputType="textPassword" android:padding="16dp" android:layout_below="@+id/et_username"/> <Button android:id="@+id/btn_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录" android:layout_centerInParent="true"/> </RelativeLayout> ``` 然后是每日收支记录界面的布局文件 `activity_record.xml`: ```xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="16dp"> <TextView android:id="@+id/tv_date" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="日期"/> <EditText android:id="@+id/et_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="项目名称"/> <EditText android:id="@+id/et_amount" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="金额"/> <Spinner android:id="@+id/sp_category" android:layout_width="match_parent" android:layout_height="wrap_content" android:entries="@array/categories" android:prompt="@string/category_prompt"/> <RadioGroup android:id="@+id/rg_payment_method" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:id="@+id/rb_credit_card" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="信用卡"/> <RadioButton android:id="@+id/rb_cash" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="现金"/> </RadioGroup> <Button android:id="@+id/btn_save" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="保存"/> <Button android:id="@+id/btn_add_note" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="添加备注"/> <ListView android:id="@+id/lv_records" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> ``` 然后是统计查询界面的布局文件 `activity_statistics.xml`: ```xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="16dp"> <RadioGroup android:id="@+id/rg_time_period" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android:id="@+id/rb_day" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="每日"/> <RadioButton android:id="@+id/rb_month" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="每月"/> <RadioButton android:id="@+id/rb_year" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="每年"/> </RadioGroup> <EditText android:id="@+id/et_start_date" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="开始日期"/> <EditText android:id="@+id/et_end_date" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="结束日期"/> <Button android:id="@+id/btn_query" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="查询"/> <TextView android:id="@+id/tv_result" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="查询结果"/> </LinearLayout> ``` 下面是 `MainActivity.java` 的代码,用于处理登录界面和主界面的切换: ```java public class MainActivity extends AppCompatActivity { private EditText etUsername, etPassword; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); etUsername = findViewById(R.id.et_username); etPassword = findViewById(R.id.et_password); Button btnLogin = findViewById(R.id.btn_login); btnLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String username = etUsername.getText().toString(); String password = etPassword.getText().toString(); // 进行登录验证 Intent intent = new Intent(MainActivity.this, RecordActivity.class); startActivity(intent); finish(); } }); } } ``` 下面是 `RecordActivity.java` 的代码,用于处理每日收支记录界面: ```java public class RecordActivity extends AppCompatActivity { private ListView lvRecords; private List<Record> recordList; private RecordAdapter recordAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_record); lvRecords = findViewById(R.id.lv_records); recordList = new ArrayList<>(); recordAdapter = new RecordAdapter(this, recordList); lvRecords.setAdapter(recordAdapter); Button btnSave = findViewById(R.id.btn_save); btnSave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // 保存记录 Record record = new Record(); // 设置记录的各个属性 recordList.add(0, record); recordAdapter.notifyDataSetChanged(); } }); Button btnAddNote = findViewById(R.id.btn_add_note); btnAddNote.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // 添加备注 } }); // 初始化日期 TextView tvDate = findViewById(R.id.tv_date); tvDate.setText(getCurrentDate()); } private String getCurrentDate() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); return sdf.format(new Date()); } private class Record { public String name; public double amount; public String date; public String category; public boolean creditCard; // 其他属性和方法 } private class RecordAdapter extends ArrayAdapter<Record> { public RecordAdapter(Context context, List<Record> recordList) { super(context, R.layout.list_item_record, recordList); } @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_record, parent, false); } // 获取该位置的记录 Record record = getItem(position); // 设置记录的各个属性到界面上的控件上 return convertView; } } } ``` 最后是 `StatisticsActivity.java` 的代码,用于处理统计查询界面: ```java public class StatisticsActivity extends AppCompatActivity { private RadioGroup rgTimePeriod; private EditText etStartDate, etEndDate; private TextView tvResult; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_statistics); rgTimePeriod = findViewById(R.id.rg_time_period); etStartDate = findViewById(R.id.et_start_date); etEndDate = findViewById(R.id.et_end_date); tvResult = findViewById(R.id.tv_result); Button btnQuery = findViewById(R.id.btn_query); btnQuery.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // 查询统计结果 String timePeriod = ((RadioButton) findViewById(rgTimePeriod.getCheckedRadioButtonId())).getText().toString(); String startDate = etStartDate.getText().toString(); String endDate = etEndDate.getText().toString(); // 根据时间段查询数据库或者文件系统中的记录,并计算统计结果 tvResult.setText("统计结果"); } }); } } ``` 至于如何将记录保存到 SQLite 或文件系统中,可以参考 Android 开发文档中的相关章节。

相关推荐

最新推荐

recommend-type

详解Android Studio实现用户登陆界面demo(xml实现)

主要介绍了详解Android Studio实现用户登陆界面demo,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
recommend-type

Android中使用Kotlin实现一个简单的登录界面

Kotlin 是一种在 Java 虚拟机上运行的静态类型编程语言,被称之为 Android 世界的Swift,由 JetBrains 设计开发并开源。接下来本文通过实例代码给大家讲解Android中使用Kotlin实现一个简单的登录界面,一起看看吧
recommend-type

Android Studio实现简单的QQ登录界面的示例代码

主要介绍了Android Studio实现简单的QQ登录界面的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
recommend-type

Android Studio 利用Splash制作APP启动界面的方法

主要介绍了Android Studio 利用Splash制作APP启动界面,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
recommend-type

解决Android Studio Log.v和Log.d不显示的问题

主要介绍了解决Android Studio Log.v和Log.d不显示的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用matlab绘制高斯色噪声情况下的频率估计CRLB,其中w(n)是零均值高斯色噪声,w(n)=0.8*w(n-1)+e(n),e(n)服从零均值方差为se的高斯分布

以下是用matlab绘制高斯色噪声情况下频率估计CRLB的代码: ```matlab % 参数设置 N = 100; % 信号长度 se = 0.5; % 噪声方差 w = zeros(N,1); % 高斯色噪声 w(1) = randn(1)*sqrt(se); for n = 2:N w(n) = 0.8*w(n-1) + randn(1)*sqrt(se); end % 计算频率估计CRLB fs = 1; % 采样频率 df = 0.01; % 频率分辨率 f = 0:df:fs/2; % 频率范围 M = length(f); CRLB = zeros(M,1); for
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。