一、支出管理界面
1、界面效果

2、前期准备
2.1 展开工程中的 bean 文件夹,打开收入信息类 IncomeBean 文件,添加 implements Serializable 即可。代码如下,
public class OutpayBean implements Serializable ……图片如下:
(2)展开工程中的 adapter 文件夹,打开收入信息适配器 OutpayAdapter 类文件,添加如下代码:
//完善:单击某一个条目,跳转到收入管理页面 mholder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //跳转到收入管理页面的代码 Intent intent=new Intent(mcontext, OutManageActivity.class); intent.putExtra("sero",outpayBean); mcontext.startActivity(intent); ((Activity)mcontext).finish(); } });
3、支出管理布局界面 activity_out_manage.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:background="@drawable/outmanagebg"
tools:context=".other.OutManageActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="190dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="金 额:"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"/>
<EditText
android:id="@+id/et_money_outmag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="0.00"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="日 期:"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"/>
<EditText
android:id="@+id/et_time_outmag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="2020-05-12"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="类 型:"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"/>
<Spinner
android:id="@+id/sp_type_outmag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/paytype"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="收款方:"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"/>
<EditText
android:id="@+id/et_payer_outmag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="海明有限公司"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="备 注:"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"/>
<EditText
android:id="@+id/et_remark_outmag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="远程技术指导费"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"/>
</LinearLayout>
<Button
android:id="@+id/bt_modify_outmag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="修改"
android:textSize="20sp"
android:textColor="#ffffff"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:background="@drawable/btn_style_one"
android:layout_marginTop="40dp"/>
<Button
android:id="@+id/bt_delete_outmag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="删除"
android:textSize="20sp"
android:textColor="#000000"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:background="@drawable/btn_style_two"
android:layout_marginTop="20dp"/>
</LinearLayout>
4、支出管理类文件 OutManageActivity.java
public class OutManageActivity extends AppCompatActivity {
//1 定义对象
private EditText et_money,et_time,et_payer,et_remark;
private Spinner sp_type;
private Button btn_modify,btn_delete;
private MyDBHelper mhelper;
private SQLiteDatabase db;
private OutpayBean outpayBean;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_out_manage);
//2 绑定控件
initView();
//3 获取单击的那条数据并显示出来
getDataDisplay();
//4 修改按钮功能的实现
btnModidfy();
//5 删除按钮功能的实现
btnDelete();
}
//2 绑定控件-----------------------代码
private void initView() {
et_money=findViewById(R.id.et_money_outmag);
et_time=findViewById(R.id.et_time_outmag);
sp_type=findViewById(R.id.sp_type_outmag);
et_payer=findViewById(R.id.et_payer_outmag);
et_remark=findViewById(R.id.et_remark_outmag);
btn_modify=findViewById(R.id.bt_modify_outmag);
btn_delete=findViewById(R.id.bt_delete_outmag);
mhelper=new MyDBHelper(OutManageActivity.this);
db=mhelper.getWritableDatabase();
}
//3 获取单击的那条数据并显示出来--------------------代码
private void getDataDisplay() {
outpayBean= (OutpayBean) getIntent().getSerializableExtra("sero");
et_money.setText(outpayBean.getMoney()+"");
et_time.setText(outpayBean.getTime());
//sp_type.setPrompt(incomeBean.getType());
if (outpayBean.getType().equals("电影-娱乐")){
sp_type.setSelection(1);
}else if (outpayBean.getType().equals("美食-畅饮")) {
sp_type.setSelection(2);
}else if (outpayBean.getType().equals("欢乐-购物")){
sp_type.setSelection(3);
}else if (outpayBean.getType().equals("手机-充值")){
sp_type.setSelection(4);
}else if (outpayBean.getType().equals("交通-出行")){
sp_type.setSelection(5);
}else if (outpayBean.getType().equals("教育-培训")){
sp_type.setSelection(6);
}else if (outpayBean.getType().equals("社交-礼仪")){
sp_type.setSelection(7);
} else if(outpayBean.getType().equals("生活-日用")){
sp_type.setSelection(8);
}else if(outpayBean.getType().equals("其他")){
sp_type.setSelection(9);
}else {
sp_type.setSelection(0);
}
et_payer.setText(outpayBean.getPayer());
et_remark.setText(outpayBean.getRemark());
}
//4 修改按钮功能的实现--------------------代码
private void btnModidfy() {
btn_modify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//创建一个对象,封装一行数据
ContentValues values=new ContentValues();
values.put("outmoney",et_money.getText().toString());
values.put("outtime",et_time.getText().toString());
values.put("outtype",sp_type.getSelectedItem().toString());
values.put("outpayee",et_payer.getText().toString());
values.put("outremark",et_remark.getText().toString());
//把该行数据更新到到支出表中
db.update("pay_out",values,"id=?",new String[]{outpayBean.getId()+""});
Toast.makeText(OutManageActivity.this,"修改成功",Toast.LENGTH_SHORT).show();
//关闭本页面,重新打开支出明细界面,即可查询修改后的结果
// 创建 Intent 对象
Intent intent=new Intent(OutManageActivity.this, PayDetailActivity.class);
startActivity(intent);// 执行 Intent 操作
finish();//退出当前程序,或关闭当前页面
}
});
}
//5 删除按钮功能的实现-------------------代码
private void btnDelete() {
btn_delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//从数据库中删除条记录即可
db.delete("pay_out","id=?",new String[]{outpayBean.getId()+""});
Toast.makeText(OutManageActivity.this,"删除成功",Toast.LENGTH_SHORT).show();
//关闭本页面,重新打开支出明细界面,即可删除后的结果
// 创建 Intent 对象
Intent intent=new Intent(OutManageActivity.this, PayDetailActivity.class);
startActivity(intent);// 执行 Intent 操作
finish();//退出当前程序,或关闭当前页面
}
});
}
}
本文档详细介绍了Android应用中支出管理界面的实现过程,包括支出信息类的序列化、收入信息适配器的点击事件处理、支出管理布局界面的XML设计以及`OutManageActivity`类的功能实现,如数据显示、修改和删除功能。


1000

被折叠的 条评论
为什么被折叠?



