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

时间: 2023-06-19 09:04:08 浏览: 47
以下是一个简单的 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

【实战演练】MATLAB用遗传算法改进粒子群GA-PSO算法

![MATLAB智能算法合集](https://static.fuxi.netease.com/fuxi-official/web/20221101/83f465753fd49c41536a5640367d4340.jpg) # 2.1 遗传算法的原理和实现 遗传算法(GA)是一种受生物进化过程启发的优化算法。它通过模拟自然选择和遗传机制来搜索最优解。 **2.1.1 遗传算法的编码和解码** 编码是将问题空间中的解表示为二进制字符串或其他数据结构的过程。解码是将编码的解转换为问题空间中的实际解的过程。常见的编码方法包括二进制编码、实数编码和树形编码。 **2.1.2 遗传算法的交叉和
recommend-type

openstack的20种接口有哪些

以下是OpenStack的20种API接口: 1. Identity (Keystone) API 2. Compute (Nova) API 3. Networking (Neutron) API 4. Block Storage (Cinder) API 5. Object Storage (Swift) API 6. Image (Glance) API 7. Telemetry (Ceilometer) API 8. Orchestration (Heat) API 9. Database (Trove) API 10. Bare Metal (Ironic) API 11. DNS
recommend-type

JSBSim Reference Manual

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