//点击添加时,添加一个新的账单分别到数据库和list中,以对话框的形式
add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); LayoutInflater inflater = LayoutInflater.from(MainActivity.this); final View viewDialog = inflater.inflate(R.layout.new_cost_data, null); final EditText title = (EditText) viewDialog.findViewById(R.id.et_cost_title); final EditText date = (EditText) viewDialog.findViewById(R.id.et_cost_date); final EditText money = (EditText) viewDialog.findViewById(R.id.et_cost_money); builder.setView(viewDialog); builder.setTitle("新的花费"); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { CostBean costBean = new CostBean(); costBean.costTitle = title.getText().toString(); costBean.costMoney = money.getText().toString(); costBean.costDate = date.getText().toString(); //加入一个新的账单并实时更新 databaseHelper.insertCost(costBean); costBeans.add(costBean); costListAdapter.notifyDataSetChanged(); } }); builder.setNegativeButton("Cancel", null); builder.create().show(); }});
评论